from datetime import datetime, timezone DEFAULT_TIME_ZONE = timezone.utc def utcnow(): return datetime.now(timezone.utc) def as_utc(value): if value.tzinfo is None: value = value.replace(tzinfo=DEFAULT_TIME_ZONE) return value.astimezone(timezone.utc) def as_local(value): return value.astimezone(DEFAULT_TIME_ZONE) def start_of_local_day(): return utcnow().astimezone(DEFAULT_TIME_ZONE).replace(hour=0, minute=0, second=0, microsecond=0)