
    xZi                     ^   S r SSKrSr\S   \S   -
  S:X  d   e\R                  " SSS5      r\R                  " SSS	5      r\R                  " SSS
5      rSr " S S\5      r " S S\5      r	 " S S\5      r
 " S S\5      r " S S\5      r " S S\5      rS rS rS rSrS rS rS rg)a  
Tools for working with dates and times in Excel files.

The conversion from ``days`` to ``(year, month, day)`` starts with
an integral "julian day number" aka JDN.
FWIW:

- JDN 0 corresponds to noon on Monday November 24 in Gregorian year -4713.

More importantly:

- Noon on Gregorian 1900-03-01 (day 61 in the 1900-based system) is JDN 2415080.0
- Noon on Gregorian 1904-01-02 (day  1 in the 1904-based system) is JDN 2416482.0

    N)i$ ia$    i  ip  ik           )i$- i- c                       \ rS rSrSrSrg)XLDateError#   z-A base class for all datetime-related errors. N__name__
__module____qualname____firstlineno____doc____static_attributes__r
       e/var/www/eduai.edurigo.com/question_generate/ques_gen_env/lib/python3.13/site-packages/xlrd/xldate.pyr   r   #   s    3r   r   c                       \ rS rSrSrSrg)XLDateNegative'   z``xldate < 0.00``r
   Nr   r
   r   r   r   r   '   s    r   r   c                       \ rS rSrSrSrg)XLDateAmbiguous+   zGThe 1900 leap-year problem ``(datemode == 0 and 1.0 <= xldate < 61.0)``r
   Nr   r
   r   r   r   r   +   s    Mr   r   c                       \ rS rSrSrSrg)XLDateTooLarge/   zGregorian year 10000 or laterr
   Nr   r
   r   r   r   r   /   s    #r   r   c                       \ rS rSrSrSrg)XLDateBadDatemode3   z#``datemode`` arg is neither 0 nor 1r
   Nr   r
   r   r   r   r   3   s    )r   r   c                       \ rS rSrSrg)XLDateBadTuple7   r
   N)r   r   r   r   r   r
   r   r   r!   r!   7   s    r   r!   c                 l   US;  a  [        U5      eU S:X  a  gU S:  a  [        U 5      e[        U 5      nX-
  n[        [        US-  5      5      nSUs=::  a  S::  d   e   eUS:X  a  S=n=pgUS-  nO[	        US5      u  p[	        US5      u  pVU[
        U   :  a  [        U 5      eUS:X  a  SSSXVU4$ US	:  a  US:X  a  [        U 5      eU[        U   -   n	U	S
-  S-   S-  S-  S
-  U	-   S-   S
-  S-   n
U
S-  S
-  S-  S-   nUS-  S-  S-   nUS-  nUS:  a  U
S-  S-
  US-
  XXg4$ U
S-  S-
  US-   XXg4$ )a  
Convert an Excel number (presumed to represent a date, a datetime or a time) into
a tuple suitable for feeding to datetime or mx.DateTime constructors.

:param xldate: The Excel number
:param datemode: 0: 1900-based, 1: 1904-based.
:raises xlrd.xldate.XLDateNegative:
:raises xlrd.xldate.XLDateAmbiguous:

:raises xlrd.xldate.XLDateTooLarge:
:raises xlrd.xldate.XLDateBadDatemode:
:raises xlrd.xldate.XLDateError:
:returns: Gregorian ``(year, month, day, hour, minute, nearest_second)``.

.. warning::

  When using this function to interpret the contents of a workbook, you
  should pass in the :attr:`~xlrd.book.Book.datemode`
  attribute of that workbook. Whether the workbook has ever been anywhere
  near a Macintosh is irrelevant.

.. admonition:: Special case

    If ``0.0 <= xldate < 1.0``, it is assumed to represent a time;
    ``(0, 0, 0, hour, minute, second)`` will be returned.

.. note::

    ``1904-01-01`` is not regarded as a valid date in the ``datemode==1``
    system; its "serial number" is zero.
r   r           )r   r   r   r   r   r   g     @r   iQ r   <   =      ie/ i:    iS    i  iM  i @     
   ik  	   l  )	r   r   introunddivmod_XLDAYS_TOO_LARGEr   r   
_JDN_delta)xldatedatemodexldaysfracsecondshourminutesecondminutesjdnyregmpds                r   xldate_as_tuplerA   ;   s   @ v))~!}V$$[F?D%w'(G 5     %!"""v! !"-gr*"8,,V$${1av..{x1}f%%
:h'
'CQwF*a/14;dBaG!KD$;1
	#c	)B
u*	!A2IB	Rx%rAvqGG%rAvqGGr   c                     U(       a  [         nOU S:  a  [        nO[        n[        U 5      nX-
  n[        [	        US-  5      5      n[        US5      u  pVU[        R                  " X5SU5      -   $ )z
Convert an Excel date/time number into a :class:`datetime.datetime` object.

:param xldate: The Excel number
:param datemode: 0: 1900-based, 1: 1904-based.

:returns: A :class:`datetime.datetime` object.
r&   g    pAi  r   )
epoch_1904
epoch_1900epoch_1900_minus_1r/   r0   r1   datetime	timedelta)r4   r5   epochdaysfractionr8   millisecondss          r   xldate_as_datetimerL      sp     B;E 'E v;D}H %:-./G"7D1G8%%dQEEEr   c                 F    U S-  (       a  gU S-  (       a  gU S-  (       a  gg)Nr(   r   d   r   i  r
   )ys    r   _leaprP      s     1uQ3wq3wqr   )Nr      r   r   r   r   r   r   r   r   r   r   c                 v   U u  p#nUS;  a  [        U5      eUS:X  a  US:X  a  US:X  a  gSUs=::  a  S::  d  O  [        SX#U4< 35      eSUs=::  a  S::  d  O  [        S	X#U4< 35      eUS:  d)  U[        U   :  a-  US
:X  a  US:X  a  [        U5      (       d  [        SX#U4< 35      eUS-   nUnUS::  a  US-
  nUS-   nOUS-
  nSU-  S-  SU-  S-   S-  -   U-   S-
  US-   S-  S-  S-  -
  nU[        U   -
  n	U	S::  a  [        SX#U4< 35      eU	S:  a  US:X  a  [        SX#U4< 35      e[        U	5      $ )a  
Convert a date tuple (year, month, day) to an Excel date.

:param year: Gregorian year.
:param month: ``1 <= month <= 12``
:param day: ``1 <= day <= last day of that (year, month)``
:param datemode: 0: 1900-based, 1: 1904-based.
:raises xlrd.xldate.XLDateAmbiguous:
:raises xlrd.xldate.XLDateBadDatemode:
:raises xlrd.xldate.XLDateBadTuple:
  ``(year, month, day)`` is too early/late or has invalid component(s)
:raises xlrd.xldate.XLDateError:
r$   r   r%   il  i'  zInvalid year: r   r   zInvalid month:       zInvalid day: r.   r-   r)   r*   r(   i         iT     rN   zInvalid (year, month, day): r'   zBefore 1900-03-01: )r   r!   _days_in_monthrP   r3   r   float)

date_tupler5   yearmonthdayYpMMpr=   r6   s
             r   xldate_from_date_tuplera      s    "Dv))qyUaZC1HD D D3EGHH"T#4FHII	q
u%
%cRiEQJ5QU;;42DFGG	BAAv!VUU"9>sRx"}3
4SS(A-24C:h''F{$sASUVV{x1}$s9KMNN=r   c                     U u  pnSUs=::  a  S:  a4  O  O1SUs=::  a  S:  a$  O  O!SUs=::  a  S:  a  O  OUS-  U-   S-  U-   S-  $ [        SXU4< 35      e)a  
Convert a time tuple ``(hour, minute, second)`` to an Excel "date" value
(fraction of a day).

:param hour: ``0 <= hour < 24``
:param minute: ``0 <= minute < 60``
:param second: ``0 <= second < 60``
:raises xlrd.xldate.XLDateBadTuple: Out-of-range hour, minute, or second
r      r&   g      N@g      8@z Invalid (hour, minute, second): )r!   )
time_tupler9   r:   r;   s       r   xldate_from_time_tuplere      sc     &D&D~2~!v**qF/?R/?$'4/$6$>>
$PVAWY
ZZr   c                 >    [        U SS U5      [        U SS 5      -   $ )a  
Convert a datetime tuple ``(year, month, day, hour, minute, second)`` to an
Excel date value.
For more details, refer to other xldate_from_*_tuple functions.

:param datetime_tuple: ``(year, month, day, hour, minute, second)``
:param datemode: 0: 1900-based, 1: 1904-based.
Nr)   )ra   re   )datetime_tupler5   s     r   xldate_from_datetime_tuplerh      s.     	~bq18<~ab12	3r   )r   rF   r3   rC   rD   rE   r2   
ValueErrorr   r   r   r   r   r!   rA   rL   rP   rX   ra   re   rh   r
   r   r   <module>rj      s    (
!}z!}$, ,, tQ*
tR,
&&tR4  . 4* 4[ Nk N$[ $* *	[ 	DHNFD H,^[ r   