File: timezone.py

package info (click to toggle)
python-model-bakery 1.20.5-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 532 kB
  • sloc: python: 4,298; sh: 149; makefile: 21
file content (13 lines) | stat: -rw-r--r-- 345 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
"""Utility functions to manage timezone code."""

from datetime import datetime, timezone

from django.conf import settings


def tz_aware(value: datetime) -> datetime:
    """Return an UTC-aware datetime in case of USE_TZ=True."""
    if settings.USE_TZ:
        return value.replace(tzinfo=timezone.utc)

    return value.replace(tzinfo=None)