§
    ‰eîi‰  ã                   ó   — U d Z ddlZddlZddlmZ ddlmZ ddlmZ  ej        e	¦  «        Z
	 ddlmZ n# e$ r	 ddlmZ Y nw xY wdaee         ed<   daee         ed<   d	aeed
<   defd„Zdedee         fd„Zdee         fd„Zdefd„ZdS )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)Úget_config_path)ÚOptional)ÚZoneInfoÚ
_cached_tzÚ_cached_tz_nameFÚ_cache_resolvedÚreturnc                  óî  — t          j        dd¦  «                             ¦   «         } | r| S 	 ddl}t	          ¦   «         }|                     ¦   «         r‘t          |¦  «        5 }|                     |¦  «        pi }ddd¦  «         n# 1 swxY w Y   |                     dd¦  «        }t          |t          ¦  «        r(|                     ¦   «         r|                     ¦   «         S n# t          $ r Y nw xY wdS )zÌRead 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Ú r   NÚtimezone)ÚosÚgetenvÚstripÚyamlr   ÚexistsÚopenÚ	safe_loadÚgetÚ
isinstanceÚstrÚ	Exception)Útz_envr   Úconfig_pathÚfÚcfgÚtz_cfgs         ú-/home/div/.hermes/hermes-agent/hermes_time.pyÚ_resolve_timezone_namer    %   s<  € õ ŒYÐ(¨"Ñ-Ô-×3Ò3Ñ5Ô5€FØð Øˆð
ØˆˆˆÝ%Ñ'Ô'ˆØ×ÒÑÔð 	&Ý�kÑ"Ô"ð . aØ—n’n QÑ'Ô'Ð-¨2�ð.ð .ð .ñ .ô .ð .ð .ð .ð .ð .ð .øøøð .ð .ð .ð .à—W’W˜Z¨Ñ,Ô,ˆFÝ˜&¥#Ñ&Ô&ð &¨6¯<ª<©>¬>ð &Ø—|’|‘~”~Ð%øøÝð ð ð Øˆðøøøð ˆ2s6   ­5C% Á"BÁ:C% ÂB
Â
C% ÂB
ÂAC% Ã%
C2Ã1C2Únamec                 ó    — | sdS 	 t          | ¦  «        S # t          t          f$ r'}t                               d| |¦  «         Y d}~dS d}~ww xY w)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'   @   sq   € àð ØˆtðÝ˜‰~Œ~ÐøÝ•iÐ ð ð ð Ý�ŠØKØ�#ñ	
ô 	
ð 	
ð ˆtˆtˆtˆtˆtøøøøðøøøs   † •A¦AÁAc                  óf   — t           s$t          ¦   «         at          t          ¦  «        ada t          S )z—Return the user's configured ZoneInfo, or None (meaning server-local).

    Resolved once and cached. Call ``reset_cache()`` after config changes.
    T)r	   r    r   r'   r   © ó    r   Úget_timezoner+   N   s/   € õ ð Ý0Ñ2Ô2ˆÝ"¥?Ñ3Ô3ˆ
ØˆÝÐr*   c                  ó”   — t          ¦   «         } | �t          j        | ¦  «        S t          j        ¦   «                              ¦   «         S )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()``).
    )r+   r   ÚnowÚ
astimezone)Útzs    r   r-   r-   [   s:   € õ 
‰Œ€BØ	€~ÝŒ|˜BÑÔÐåŒ<‰>Œ>×$Ò$Ñ&Ô&Ð&r*   )Ú__doc__Úloggingr   r   Úhermes_constantsr   Útypingr   Ú	getLoggerÚ__name__r$   Úzoneinfor   ÚImportErrorÚbackports.zoneinfor   Ú__annotations__r   r   r	   Úboolr    r'   r+   r-   r)   r*   r   ú<module>r;      s  ððð ð ð €€€Ø 	€	€	€	Ø Ð Ð Ð Ð Ð Ø ,Ð ,Ð ,Ð ,Ð ,Ð ,Ø Ð Ð Ð Ð Ð à	ˆÔ	˜8Ñ	$Ô	$€ð,Ø!Ð!Ð!Ð!Ð!Ð!Ð!øØð ,ð ,ð ,à+Ð+Ð+Ð+Ð+Ð+Ð+Ð+ð,øøøð "&€
ˆH�XÔÐ %Ð %Ñ %Ø!%€�˜#”Ð %Ð %Ñ %Ø€�Ð Ð Ñ ð ð ð ð ð ð6˜ð  ¨Ô 2ð ð ð ð ð
�h˜xÔ(ð 
ð 
ð 
ð 
ð'ˆXð 'ð 'ð 'ð 'ð 'ð 's   ¯6 ¶AÁA