module documentation

Timezone-related classes and functions.

Class override Temporarily set the time zone for the current thread.
Function __dir__ Undocumented
Function __getattr__ Undocumented
Function activate Set the time zone for the current thread.
Function deactivate Unset the time zone for the current thread.
Function get_current_timezone Return the currently active time zone as a tzinfo instance.
Function get_current_timezone_name Return the name of the currently active time zone.
Function get_default_timezone Return the default time zone as a tzinfo instance.
Function get_default_timezone_name Return the name of the default time zone.
Function get_fixed_timezone Return a tzinfo instance with a fixed offset from UTC.
Function is_aware Determine if a given datetime.datetime is aware.
Function is_naive Determine if a given datetime.datetime is naive.
Function localdate Convert an aware datetime to local time and return the value's date.
Function localtime Convert an aware datetime.datetime to local time.
Function make_aware Make a naive datetime.datetime in a given time zone aware.
Function make_naive Make an aware datetime.datetime naive in a given time zone.
Function now Return an aware or naive datetime.datetime, depending on settings.USE_TZ.
Function template_localtime Check if value is a datetime and converts it to local time if necessary.
Constant NOT_PASSED Undocumented
Function _datetime_ambiguous_or_imaginary Undocumented
Function _get_timezone_name Return the offset for fixed offset timezones, or the name of timezone if not set.
Function _is_pytz_zone Checks if a zone is a pytz zone.
Function _pytz_imported Detects whether or not pytz has been imported without importing pytz.
Constant _DIR Undocumented
Constant _PYTZ_IMPORTED Undocumented
Variable _active Undocumented
def __dir__(): (source)

Undocumented

def __getattr__(name): (source)

Undocumented

def activate(timezone): (source)

Set the time zone for the current thread. The ``timezone`` argument must be an instance of a tzinfo subclass or a time zone name.

def deactivate(): (source)

Unset the time zone for the current thread. Django will then use the time zone defined by settings.TIME_ZONE.

def get_current_timezone(): (source)

Return the currently active time zone as a tzinfo instance.

def get_current_timezone_name(): (source)

Return the name of the currently active time zone.

@functools.lru_cache
def get_default_timezone(): (source)

Return the default time zone as a tzinfo instance. This is the time zone defined by settings.TIME_ZONE.

def get_default_timezone_name(): (source)

Return the name of the default time zone.

def get_fixed_timezone(offset): (source)

Return a tzinfo instance with a fixed offset from UTC.

def is_aware(value): (source)

Determine if a given datetime.datetime is aware. The concept is defined in Python's docs: https://docs.python.org/library/datetime.html#datetime.tzinfo Assuming value.tzinfo is either None or a proper datetime.tzinfo, value.utcoffset() implements the appropriate logic.

def is_naive(value): (source)

Determine if a given datetime.datetime is naive. The concept is defined in Python's docs: https://docs.python.org/library/datetime.html#datetime.tzinfo Assuming value.tzinfo is either None or a proper datetime.tzinfo, value.utcoffset() implements the appropriate logic.

def localdate(value=None, timezone=None): (source)

Convert an aware datetime to local time and return the value's date. Only aware datetimes are allowed. When value is omitted, it defaults to now(). Local time is defined by the current time zone, unless another time zone is specified.

def localtime(value=None, timezone=None): (source)

Convert an aware datetime.datetime to local time. Only aware datetimes are allowed. When value is omitted, it defaults to now(). Local time is defined by the current time zone, unless another time zone is specified.

def make_aware(value, timezone=None, is_dst=NOT_PASSED): (source)

Make a naive datetime.datetime in a given time zone aware.

def make_naive(value, timezone=None): (source)

Make an aware datetime.datetime naive in a given time zone.

def now(): (source)

Return an aware or naive datetime.datetime, depending on settings.USE_TZ.

def template_localtime(value, use_tz=None): (source)

Check if value is a datetime and converts it to local time if necessary. If use_tz is provided and is not None, that will force the value to be converted (or not), overriding the value of settings.USE_TZ. This function is designed for use by the template engine.

NOT_PASSED = (source)

Undocumented

Value
object()
def _datetime_ambiguous_or_imaginary(dt, tz): (source)

Undocumented

def _get_timezone_name(timezone): (source)

Return the offset for fixed offset timezones, or the name of timezone if not set.

def _is_pytz_zone(tz): (source)

Checks if a zone is a pytz zone.

def _pytz_imported(): (source)

Detects whether or not pytz has been imported without importing pytz. Copied from pytz_deprecation_shim with thanks to Paul Ganssle.

Undocumented

Value
dir()
_PYTZ_IMPORTED: bool = (source)

Undocumented

Value
False

Undocumented