MCPcopy
hub / github.com/agent0ai/agent-zero / __init__

Method __init__

helpers/localization.py:27–52  ·  view source on GitHub ↗
(self, timezone: str | None = None)

Source from the content-addressed store, hash-verified

25 return cls._instance
26
27 def __init__(self, timezone: str | None = None):
28 self.timezone: str = "UTC"
29 self._offset_minutes: int = 0
30 self._last_timezone_change: datetime | None = None
31 # Load persisted values if available.
32 persisted_tz = str(get_dotenv_value("DEFAULT_USER_TIMEZONE", os.environ.get("TZ") or "UTC"))
33 persisted_offset = get_dotenv_value("DEFAULT_USER_UTC_OFFSET_MINUTES", None)
34 if timezone is not None:
35 # Explicit override
36 self.set_timezone(timezone)
37 else:
38 # Initialize from persisted values
39 try:
40 pytz.timezone(persisted_tz)
41 self.timezone = persisted_tz
42 except pytz.exceptions.UnknownTimeZoneError:
43 self.timezone = "UTC"
44 current_offset = self._compute_offset_minutes(self.timezone)
45 try:
46 persisted_offset_minutes = int(str(persisted_offset)) if persisted_offset is not None else None
47 except Exception:
48 persisted_offset_minutes = None
49 self._offset_minutes = current_offset
50 if persisted_offset_minutes != current_offset:
51 save_dotenv_value("DEFAULT_USER_UTC_OFFSET_MINUTES", str(self._offset_minutes))
52 self.apply_process_timezone()
53
54 def get_timezone(self) -> str:
55 return self.timezone

Callers

nothing calls this directly

Calls 6

set_timezoneMethod · 0.95
get_dotenv_valueFunction · 0.90
save_dotenv_valueFunction · 0.90
getMethod · 0.45

Tested by

no test coverage detected