
    R1g_                        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	Zd
edefdZd
eddfdZdedefdZdedededej                  fdZdeddfdZg dZy)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           	          |dk  s|dkD  rt        d      t        t        j                  t        t        | |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).   )freqdtstart	byweekdaycount)
ValueErrorr   datetimer   r   )r   r   s     d/var/www/trellinator.diamondhoofcare.com/public_html/venv/lib/python3.12/site-packages/arrow/util.pynext_weekdayr      sF    . {gkMNN6:J1M     valuec                     t        | t              ryt        | t        t        t        f      sy	 t        |        y# t
        $ r Y yw xY w)z$Check if value is a valid timestamp.FT)
isinstanceboolintfloatstrr   r   s    r   is_timestampr$   0   sD    %ec5#./e s   ; 	AAc                     t        | t              st        | t              st        dt	        |        d      t
        | cxk  r	t        k  sn t        d|  d      y)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#   s    r   validate_ordinalr(   =   sW     %j&<?U}BOPP5/K/8E7*;<== 0r   	timestampc                 v    | t         kD  r/| t        k  r| dz  } | S | t        k  r| dz  } | 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)   s    r   normalize_timestampr+   I   s_    = ''I
 	 ))"I  7	}NSTTr   iso_yeariso_weekiso_dayc                 R   d|cxk  rdk  st        d       t        d      d|cxk  rdk  st        d       t        d      t        j                  | dd      }t        j                  |j	                         dz
        }||z
  }|t        j                  |dz
  |dz
        z   }|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.   
fourth_jandelta
year_start	gregorians          r   iso_to_gregorianr<   V   s     BHII HII1EFF EFF xA.Jz446:;Ee#JX//Wq[STUUIr   boundsc                 H    | dk7  r| dk7  r| dk7  r| dk7  rt        d      y y y y )Nz()z(]z[)z[]z@Invalid bounds. Please select between '()', '(]', '[)', or '[]'.)r   )r=   s    r   validate_boundsr?   n   s8    ~&D.Vt^$N
 	
 AO^.~r   )r   r$   r(   r<   )__doc__r   typingr   r   r   dateutil.rruler   r   arrow.constantsr   r	   r
   r   r   r5   r    r   r   r$   r(   r!   r+   r<   r"   r?   __all__ r   r   <module>rF      s    5  & & ( '25>
 
 
	>C 	>D 	>	5 	U 	s c C HMM 0
C 
D 
 Sr   