o
    }`_                     @   s   d Z ddlZddlmZmZmZ ddlmZmZ ddl	m
Z
mZmZmZmZ deej dedejfd	d
ZdedefddZdeddfddZdedefddZdedededejfddZdeddfddZg dZdS )z/Helpful functions used internally within arrow.    N)AnyOptionalcast)WEEKLYrrule)MAX_ORDINALMAX_TIMESTAMPMAX_TIMESTAMP_MSMAX_TIMESTAMP_USMIN_ORDINAL
start_dateweekdayreturnc                 C   s4   |dk s|dkrt dttjtt| |ddd S )a  Get next weekday from the specified start date.

    :param start_date: Datetime object representing the start date.
    :param weekday: Next weekday to obtain. Can be a value between 0 (Monday) and 6 (Sunday).
    :return: Datetime object corresponding to the next weekday after start_date.

    Usage::

        # Get first Monday after epoch
        >>> next_weekday(datetime(1970, 1, 1), 0)
        1970-01-05 00:00:00

        # Get first Thursday after epoch
        >>> next_weekday(datetime(1970, 1, 1), 3)
        1970-01-01 00:00:00

        # Get first Sunday after epoch
        >>> next_weekday(datetime(1970, 1, 1), 6)
        1970-01-04 00:00:00
    r      z2Weekday must be between 0 (Monday) and 6 (Sunday).   )freqZdtstartZ	byweekdaycount)
ValueErrorr   datetimer   r   )r   r    r   .usr/lib/python3.10/site-packages/arrow/util.pynext_weekday   s   r   valuec                 C   sF   t | trdS t | tttfsdS zt|  W dS  ty"   Y dS w )z$Check if value is a valid timestamp.FT)
isinstanceboolintfloatstrr   r   r   r   r   is_timestamp0   s   
r   c                 C   sR   t | ts
t | tstdt|  dt|   krtks'n td|  ddS )zmRaise an exception if value is an invalid Gregorian ordinal.

    :param value: the input to be checked

    z%Ordinal must be an integer (got type z).zOrdinal z is out of range.N)r   r   r   	TypeErrortyper   r   r   r   r   r   r   validate_ordinal=   s
   r"   	timestampc                 C   sD   | t kr | tk r| d } | S | tk r| d } | S td| d| S )zHNormalize millisecond and microsecond timestamps into normal timestamps.i  i@B zThe specified timestamp z is too large.)r   r	   r
   r   )r#   r   r   r   normalize_timestampI   s   r$   iso_yeariso_weekiso_dayc                 C   s   d|  krdkst d t dd|  krdks$t d t dt| dd}t| d }|| }|tj|d |d d }|S )zConverts an ISO week date into a datetime object.

    :param iso_year: the year
    :param iso_week: the week number, each year has either 52 or 53 weeks
    :param iso_day: the day numbered 1 through 7, beginning with Monday

    r   5   z-ISO Calendar week value must be between 1-53.   z*ISO Calendar day value must be between 1-7   )daysweeks)r   r   date	timedelta
isoweekday)r%   r&   r'   Z
fourth_jandeltaZ
year_startZ	gregorianr   r   r   iso_to_gregorianV   s   	r1   boundsc                 C   s8   | dkr| dkr| dkr| dkrt dd S d S d S d S )Nz()z(]z[)z[]z@Invalid bounds. Please select between '()', '(]', '[)', or '[]'.)r   )r2   r   r   r   validate_boundsn   s
    r3   )r   r   r"   r1   )__doc__r   typingr   r   r   Zdateutil.rruler   r   Zarrow.constantsr   r   r	   r
   r   r-   r   r   r   r   r"   r   r$   r1   r   r3   __all__r   r   r   r   <module>   s$    	
