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

Method set_timezone

helpers/localization.py:100–131  ·  view source on GitHub ↗

Set the user's IANA timezone and propagate it to child processes.

(self, timezone: str)

Source from the content-addressed store, hash-verified

98 return tzinfo.localize(dt, is_dst=True)
99
100 def set_timezone(self, timezone: str) -> None:
101 """Set the user's IANA timezone and propagate it to child processes."""
102 try:
103 # Validate timezone and compute its current offset
104 _ = pytz.timezone(timezone)
105 new_offset = self._compute_offset_minutes(timezone)
106 if timezone == self.timezone and new_offset == self._offset_minutes:
107 self.apply_process_timezone()
108 return
109
110 prev_tz = getattr(self, "timezone", "None")
111 prev_off = getattr(self, "_offset_minutes", None)
112 PrintStyle.debug(
113 f"Changing timezone from {prev_tz} (offset {prev_off}) to {timezone} (offset {new_offset})"
114 )
115 self._offset_minutes = new_offset
116 self.timezone = timezone
117 save_dotenv_value("DEFAULT_USER_TIMEZONE", timezone)
118 save_dotenv_value("DEFAULT_USER_UTC_OFFSET_MINUTES", str(self._offset_minutes))
119 self.apply_process_timezone()
120 self._last_timezone_change = datetime.now()
121 except pytz.exceptions.UnknownTimeZoneError:
122 fallback_timezone = self.timezone
123 try:
124 pytz.timezone(fallback_timezone)
125 except pytz.exceptions.UnknownTimeZoneError:
126 fallback_timezone = "UTC"
127
128 PrintStyle.error(f"Unknown timezone: {timezone}, keeping {fallback_timezone}")
129 self.timezone = fallback_timezone
130 self._offset_minutes = self._compute_offset_minutes(fallback_timezone)
131 self.apply_process_timezone()
132
133 def localtime_str_to_utc_dt(self, localtime_str: str | None) -> datetime | None:
134 """

Callers 10

__init__Method · 0.95
_apply_timezone_settingFunction · 0.80
processMethod · 0.80
processMethod · 0.80
processMethod · 0.80
processMethod · 0.80
processMethod · 0.80
processMethod · 0.80

Calls 6

save_dotenv_valueFunction · 0.90
debugMethod · 0.80
nowMethod · 0.45
errorMethod · 0.45