
    5pj                        % S r SSKJr  SSKrSSKrSSKJrJr  SrS\S'   \R                  " S5      r
SS	 jrSS
 jrSS jrSS.     SS jjrS/rg)z4Timestamp parsing and timezone conversion utilities.    )annotationsN)datetimetimezone)z%Y-%m-%dT%H:%M:%S.%fz%Y-%m-%dT%H:%M:%Sz%Y-%m-%d %H:%M:%S.%fz%Y-%m-%d %H:%M:%Sztuple[str, ...]_NAIVE_FORMATSz(\.\d{6})\d+c                .    [         R                  SU 5      $ )z5Truncate fractional seconds to microsecond precision.z\1)_SUBSECOND_REsub)values    [/var/www/html/pdf-tiff/venv/lib/python3.13/site-packages/modelscope_hub/utils/time_utils.py_truncate_subsecondsr      s    UE**    c                    U SS S-   n[        U5      n [        R                  " U5      nUR	                  U5      $ ! [         a  n[        SU < 35      UeSnAff = f)zAParse a trailing-Z UTC string and convert to the target timezone.Nz+00:00zInvalid UTC timestamp string: )r   r   fromisoformat
ValueError
astimezone)r
   	target_tzisodtexcs        r   _parse_utc_stringr      sn     *x
C
s
#CN##C( ==##  N9%CD#MNs   < 
AAAc                l   [        U 5      n[         H)  n [        R                  " X#5      nUR                  US9s  $     [        R                  " U5      nUR                  c  UR                  US9$ UR                  U5      $ ! [         a     M~  f = f! [         a  n[	        SU < 35      UeSnAff = f)z>Parse a naive timestamp string and attach the target timezone.tzinfozUnrecognized timestamp string: N)	r   r   r   strptimer   replacer   r   r   )r
   r   	candidatefmtr   r   s         r   _parse_naive_stringr   &   s    $U+I	""92B zzz++ O##I. 
yyzzz++==##  		  O:5)DE3NOs)   B B 
BB
B3B..B3zAsia/Shanghaitzc               B   U c  g[         R                  " U5      n[        U [        5      (       a-  U R                  c  U R                  US9$ U R                  U5      $ [        U [        5      (       a!  [        S[        U 5      R                   35      e[        U [        [        45      (       aB  U S:  a  U S-  OU n [        R                  " U[        R                  S9nUR                  U5      $ [        U [&        5      (       aN  U R)                  5       nU(       d  [%        S5      eUR+                  S	5      (       a  [-        Xb5      $ [/        Xb5      $ [        S[        U 5      R                   35      e! [         ["        [$        4 a  n[%        SU < 35      UeSnAff = f)
aK  Normalize heterogeneous timestamp inputs to a timezone-aware datetime.

Args:
    value: A UNIX timestamp (int), an ISO-like string, a datetime, or None.
    tz: IANA timezone name used as the conversion target and the default
        timezone for naive inputs.

Returns:
    A timezone-aware datetime, or None when value is None.
Nr   zUnsupported timestamp type: l   c(	 i  r    zInvalid UNIX timestamp: zEmpty timestamp stringZ)zoneinfoZoneInfo
isinstancer   r   r   r   bool	TypeErrortype__name__intfloatfromtimestampr   utcOverflowErrorOSErrorr   strstripendswithr   r   )r
   r!   r   tsr   r   texts          r   parse_timestampr6   9   sl    }!!"%I%""<<==	=22	** %6tE{7K7K6LMNN%#u&&"]2UT\	L''x||<B }}Y''%{{}566==$T55"433
24;3G3G2HI
JJ w
3 	L7yABK	Ls   <#E4 4F	FFr6   )r
   r1   returnr1   )r
   r1   r   zzoneinfo.ZoneInfor7   r   )r
   zint | str | datetime | Noner!   r1   r7   zdatetime | None)__doc__
__future__r   rer$   r   r   r   __annotations__compiler   r   r   r   r6   __all__ r   r   <module>r?      sv    : " 	  '#  

?++
	$$, -K&-K 	-K 	-K` 
r   