MCPcopy Create free account
hub / github.com/Tron521/codex-console-temp / _normalize_datetime

Function _normalize_datetime

src/core/openai/overview.py:304–327  ·  view source on GitHub ↗
(value: Any)

Source from the content-addressed store, hash-verified

302
303
304def _normalize_datetime(value: Any) -> Optional[datetime]:
305 if value is None:
306 return None
307 if isinstance(value, datetime):
308 if value.tzinfo is None:
309 return value.replace(tzinfo=timezone.utc)
310 return value.astimezone(timezone.utc)
311 number = _to_float(value)
312 if number is not None:
313 return _try_parse_epoch(number)
314 if isinstance(value, str):
315 raw = value.strip()
316 if not raw:
317 return None
318 try:
319 if raw.endswith("Z"):
320 raw = raw[:-1] + "+00:00"
321 dt = datetime.fromisoformat(raw)
322 if dt.tzinfo is None:
323 dt = dt.replace(tzinfo=timezone.utc)
324 return dt.astimezone(timezone.utc)
325 except ValueError:
326 return None
327 return None
328
329
330def _format_duration(seconds: Optional[float]) -> str:

Callers 2

_extract_quota_candidateFunction · 0.85

Calls 2

_to_floatFunction · 0.85
_try_parse_epochFunction · 0.85

Tested by

no test coverage detected