You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

datetime_utils.py 653B

12345678910111213141516171819202122
  1. import abc
  2. import datetime
  3. from typing import Protocol
  4. class _NowFunction(Protocol):
  5. @abc.abstractmethod
  6. def __call__(self, tz: datetime.timezone | None) -> datetime.datetime:
  7. pass
  8. # _now_func is a callable with the _NowFunction signature.
  9. # Its sole purpose is to abstract time retrieval, enabling
  10. # developers to mock this behavior in tests and time-dependent scenarios.
  11. _now_func: _NowFunction = datetime.datetime.now
  12. def naive_utc_now() -> datetime.datetime:
  13. """Return a naive datetime object (without timezone information)
  14. representing current UTC time.
  15. """
  16. return _now_func(datetime.UTC).replace(tzinfo=None)