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

Method serialize_datetime

helpers/localization.py:195–215  ·  view source on GitHub ↗

Serialize a datetime object to ISO format string using the user's timezone. This ensures the frontend receives dates with the correct offset for display.

(self, dt: datetime | None)

Source from the content-addressed store, hash-verified

193 return None
194
195 def serialize_datetime(self, dt: datetime | None) -> str | None:
196 """
197 Serialize a datetime object to ISO format string using the user's timezone.
198 This ensures the frontend receives dates with the correct offset for display.
199 """
200 if dt is None:
201 return None
202
203 # At this point, dt is definitely not None
204 assert dt is not None
205
206 try:
207 # Ensure datetime is timezone aware (if not, assume the user's timezone)
208 if dt.tzinfo is None:
209 dt = self.localize_naive_datetime(dt)
210
211 local_dt = dt.astimezone(self.get_tzinfo())
212 return local_dt.isoformat()
213 except Exception as e:
214 PrintStyle.error(f"Error serializing datetime: {e}")
215 return None

Callers 7

outputMethod · 0.80
executeMethod · 0.80
outputMethod · 0.80
serialize_datetimeFunction · 0.80
_serialize_contextFunction · 0.80
managed_waitFunction · 0.80

Calls 3

get_tzinfoMethod · 0.95
errorMethod · 0.45

Tested by

no test coverage detected