+
    i                       a  R t0 t R t^ RIt^ RIt^ RIHt ^ RIHt ^ RIHt ^ RI	H
t
 ]P                  ! ]4      t ^ RIHt Rs] ^ k Rs] ^k Rs] ^k R R	 ltR
 R ltR R ltR R ltR R ltR R ltR#   ] d
    ^ RIHt  LGi ; i)u  
Timezone-aware clock for Hermes.

Provides a single ``now()`` helper that returns a timezone-aware datetime
based on the user's configured IANA timezone (e.g. ``Asia/Kolkata``).

Resolution order:
  1. ``HERMES_TIMEZONE`` environment variable
  2. ``timezone`` key in ``~/.hermes/config.yaml``
  3. Falls back to the server's local time (``datetime.now().astimezone()``)

Invalid timezone values log a warning and fall back safely — Hermes never
crashes due to a bad timezone string.
Ndatetime)Path)get_hermes_home)Optional)ZoneInfoFc                $    V ^8  d   QhR\         /#    returnstr)formats   "(/home/ubuntu/hermes-agent/hermes_time.py__annotate__r   &   s           c                    \         P                  ! RR4      P                  4       p V '       d   V #  ^ RIp\	        4       pVR,          pVP                  4       '       d   \        V4      ;_uu_ 4       pVP                  V4      ;'       g    / pRRR4       XP                  RR4      p\        V\        4      '       d'   VP                  4       '       d   VP                  4       # R#   + '       g   i     L`; i  \         d     R# i ; i)zRead the configured IANA timezone string (or empty string).

This does file I/O when falling through to config.yaml, so callers
should cache the result rather than calling on every ``now()``.
HERMES_TIMEZONE Nzconfig.yamltimezone)osgetenvstripyamlr   existsopen	safe_loadget
isinstancer   	Exception)tz_envr   hermes_homeconfig_pathfcfgtz_cfgs          r   _resolve_timezone_namer&   &   s     YY("-335F%'!M1k""annQ'--2 #WWZ,F&#&&6<<>>||~%  #"
  s1   A C8 1C%AC8 C8 %C5	0C8 8DDc                F    V ^8  d   QhR\         R\        \        ,          /# )r
   namer   )r   r   r   )r   s   "r   r   r   B   s        2 r   c                    V '       g   R#  \        V 4      #   \        \        3 d"   p\        P	                  RY4        Rp?R# Rp?ii ; i)z3Validate and return a ZoneInfo, or None if invalid.Nz=Invalid timezone '%s': %s. Falling back to server local time.)r   KeyErrorr   loggerwarning)r(   excs   & r   _get_zoneinfor.   B   sC    ~i  K	
 s   
 A	AA	c                :    V ^8  d   QhR\         \        ,          /# r	   )r   r   )r   s   "r   r   r   P   s     
 
hx( 
r   c                 \    \         '       g   \        4       s\        \        4      sRs \        # )zReturn the user's configured ZoneInfo, or None (meaning server-local).

Resolved once and cached. Call ``reset_cache()`` after config changes.
T)_cache_resolvedr&   _cached_tz_namer.   
_cached_tz r   r   get_timezoner5   P   s&     ?02"?3
r   c                $    V ^8  d   QhR\         /# r	   r   )r   s   "r   r   r   ]   s     ! !3 !r   c                 N    \         '       g   \        4        \        ;'       g    R# )zAReturn the IANA name of the configured timezone, or empty string.r   )r1   r5   r2   r4   r   r   get_timezone_namer8   ]   s     ?  b r   c                $    V ^8  d   QhR\         /# r	   r   )r   s   "r   r   r   e   s     ' 'X 'r   c                     \        4       p V e   \        P                  ! V 4      # \        P                  ! 4       P                  4       # )z
Return the current time as a timezone-aware datetime.

If a valid timezone is configured, returns wall-clock time in that zone.
Otherwise returns the server's local time (via ``astimezone()``).
)r5   r   now
astimezone)tzs    r   r;   r;   e   s4     
B	~||B<<>$$&&r   c                    V ^8  d   QhRR/# )r
   r   Nr4   )r   s   "r   r   r   s   s      T r   c                     Rs RsRsR# )zBClear the cached timezone. Used by tests and after config changes.NF)r3   r2   r1   r4   r   r   reset_cacher@   s   s     JOOr   c                    V ^8  d   Qh/ ^ \         9   d   \        \        ,          ;R&   ^\         9   d   \        \        ,          ;R&   ^\         9   d
   \        ;R&   # )r
   r3   r2   r1   )__conditional_annotations__r   r   r   bool)r   s   "r   r   r      sQ      @ & %HX %AB & %# %CD   Er   )rB   __doc__loggingr   r   pathlibr   hermes_constantsr   typingr   	getLogger__name__r+   zoneinfor   ImportErrorbackports.zoneinfor3   r2   r1   r&   r.   r5   r8   r;   r@   r   )rB   s   @r   <module>rN      s     	   , 			8	$,! "&
 %!% % 8
!'q  ,+,s   A: :B
	B
