
    YOg-                         S SK r S SKrS SKJr  SSKJrJrJr  \R                  (       a  S SK
rSrSrSrSr\ " S	 S
5      5       rg)    N)	dataclass   )MatchFullError
match_full	matchiteriQ g     p>@g     v@g    .Ac                       \ rS rSr% SrSr\\S'   Sr\\S'   Sr	\\S'   Sr
\\S'   Sr\\S'   Sr\\S	'   Sr\\S
'   Sr\\S'   / SQrSS jrS\4S jrS\4S jrS\R,                  4S jrSS jr\S\SS 4S j5       rSrg)duration   a  
Represents an ISO 8601 duration.

__A note about sub-second percision__

As described [here](https://stackoverflow.com/a/50570660/791713), referencing the ISO 8601 specification,
sub-second precision must be expressed as a fraction in the lowest-order component, i.e. seconds. However,
for the reasons of backwards compatibility, as well as parallels to the Python #datetime.timedelta class, we
only store an additional #microseconds component which is extracted from the fractional representation of the
ISO 8601 duration string.
r   yearsmonthsweeksdayshoursminutessecondsmicrosecondsr   r   r   r   r   r   r   r   returnNc                 |    U R                    H,  n[        X5      S:  d  M  [        SR                  U5      5      e   g )Nr   z{} cannot be negative)_fieldsgetattr
ValueErrorformat)selfks     U/Users/admin/workspace/ai/Jarvis/env/lib/python3.13/site-packages/nr/date/duration.py__post_init__duration.__post_init__)   s4    At!# !8!?!?!BCC     c                 $   / n/ nU R                   S4U R                  S4U R                  S4U R                  S44 H-  u  p4US:w  d  M  UR	                  SR                  X45      5        M/     UR	                  SR                  U5      5        U R                  S:  a:  [        U R                  U R                  [        -  -   5      R                  SS	5      nO[        U R                  5      n/ n[        U R                  5      S
4[        U R                  5      S4US44 H-  u  p4US:w  d  M  UR	                  SR                  X45      5        M/     U(       a   UR	                  SR                  U5      5        U(       d  gSSR                  U5      -   $ )NYMWDr   z{}{} .,HS0PT0SPT)r   r   r   r   appendr   joinr   strr   MICROSECONDS_PER_SECONDreplacer   r   )r   parts
date_partsvaluecharr   
time_partss          r   __str__duration.__str__.   sV   
!ZZ-S/ADJJPSCTW[W`W`beVfgKEz!!&--"<= h 	RWWZ() q $,,):):=T)TTU]]^acfgG$,,'G
 _c2S5F4LwX[n]KE|!!&--"<= ^ LL,-SXXe_$$r   c                 D   U R                   [        -  [        -  U R                  [        -  [        -  -   U R
                  S-  [        -  -   U R                  [        -  -   U R                  S-  -   U R                  S-  -   U R                  -   U R                  [        -  -   $ )z8
Computes the total number of seconds in this duration.
   i  <   )r   DAYS_PER_YEARSECONDS_PER_DAYr   DAYS_PER_MONTHr   r   r   r   r   r   r1   r   s    r   total_secondsduration.total_secondsJ   s     JJ&8kkN*_<=jj1n./ ii/)* jj4	 
 llR  ll "99:		
r   c                 F    [         R                  " U R                  5       S9$ )z
Returns the seconds represented by this duration as a #datetime.timedelta object. The arguments
and keyword arguments are forwarded to the #total_seconds() method.
)r   )datetime	timedeltarA   r@   s    r   as_timedeltaduration.as_timedeltaZ   s     !!$*<*<*>??r   c                     SSK Jn  U" U R                  U R                  U R                  U R
                  U R                  U R                  U R                  U R                  S9$ )zy
Converts the #duration object to a #dateutil.relativedelta.relativedelta object. Requires
the `python-dateutil` module.
r   )relativedeltar   )
dateutil.relativedeltarI   r   r   r   r   r   r   r   r   )r   rI   s     r   as_relativedeltaduration.as_relativedeltab   sN     	9**;;****LLLL**	
 		
r   sc                 j   UR                  S5      nU(       a  US   S:w  d  [        U5      S:  a  [        SR                  U5      5      eUS   SS n[        U5      S:X  a  US   OSn0 n S	 [	        S
U5       5        H@  u  pg[        U5      nUS:X  a  XeS'   M  US:X  a  XeS'   M(  US:X  a  XeS'   M4  US:X  d  M<  XeS'   MB     SnS [        SU5       5        H+  u  nu  pg[        U5      nUS:X  a  XeS'   M  US:X  d  M'  XeS'   M-     XHS n	S [	        SU	5       5        H"  n[        UR                  SS5      5      nXeS'   M$     [        UR                  SS5      S5      u  p[        U
5      US'   [        U[        -  5      US'   U " S 0 UD6$ ! [         a    [        SR                  U5      5      ef = f)!z
Parses an ISO 8601 duration string into a #duration object.

Thanks to https://stackoverflow.com/a/35936407.
See also https://en.wikipedia.org/wiki/ISO_8601#Durations
r-   r   r,      z%Not an ISO 8601 duration string: {!r}r   Nr%   c              3   @   #    U  H  oR                  5       v   M     g 7fN)groups.0xs     r   	<genexpr>!duration.parse.<locals>.<genexpr>   s      ]5\5\s   z(\d+)(D|W|M|Y)r!   r   r"   r   r#   r   r$   r   c              3   `   #    U  H$  oR                  5       UR                  5       4v   M&     g 7frQ   )endrR   rS   s     r   rV   rW      s#      7/Q!!((*%/Qs   ,.z
(\d+)(H|M)r(   r   r   c              3   B   #    U  H  oR                  S 5      v   M     g7f)r   N)grouprS   s     r   rV   rW      s     ^/]!771::/]s   z(\d+(?:[,\.]\d+)?)Sr'   r&   r   g        g      ?r    )splitlenr   r   r   intr   floatr2   r   divmodgetr1   )clsrM   r3   part_onepart_twofieldsnumberunitlast_match_end_idx
part_threer   	remainders               r   parseduration.parseu   s    AaDCK3u:>DKKANOO8AB<"5zQ58B	P ]Z@QS[5\ ]V3;&,7OS['-8$S[&,7OS[%+6N !^ "#7/8/Q72"NV V3;&,7OS[(.9%7 ""56J^z:PR\/]^v~~c378$*y! _ $FJJy#$>DLy!$Y1H%H!I~}V}  	PDKKANOO	Ps   ,AF ;A F ?AF %F2r\   )r   N)r   z$dateutil.relativedelta.relativedelta)__name__
__module____qualname____firstlineno____doc__r   r_   __annotations__r   r   r   r   r   r   r   r   r   r0   r8   r`   rA   rD   rE   rF   rK   classmethodrl   __static_attributes__r\   r   r   r	   r	      s    
 E3NFCOE3ND#ME3NGSGSL#aGD
% %8
u 
 @h00 @
& 3c 3j 3 3r   r	   )rD   typingtdataclassesr   rer   r   r   TYPE_CHECKINGrJ   dateutilr>   r?   r=   r1   r	   r\   r   r   <module>r|      sO      ! 5 5??!)  X X Xr   