module documentation

Timezone-related classes and functions.
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.
Constant NOT​_PASSED Undocumented
Class override Temporarily set the time zone for the current thread.
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.
Function template​_localtime Check if value is a datetime and converts it to local time if necessary.
Constant ​_PYTZ​_IMPORTED Undocumented
Variable ​_active Undocumented
def activate(timezone):

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():

Unset the time zone for the current thread.

Django will then use the time zone defined by settings.TIME_ZONE.

def get_current_timezone():
Return the currently active time zone as a tzinfo instance.
def get_current_timezone_name():
Return the name of the currently active time zone.
@functools.lru_cache()
def get_default_timezone():

Return the default time zone as a tzinfo instance.

This is the time zone defined by settings.TIME_ZONE.

def get_default_timezone_name():
Return the name of the default time zone.
def get_fixed_timezone(offset):
Return a tzinfo instance with a fixed offset from UTC.
def is_aware(value):

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):

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):

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):

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):
Make a naive datetime.datetime in a given time zone aware.
def make_naive(value, timezone=None):
Make an aware datetime.datetime naive in a given time zone.
def now():
Return an aware or naive datetime.datetime, depending on settings.USE_TZ.
NOT_PASSED =

Undocumented

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

Undocumented

def _get_timezone_name(timezone):
Return the offset for fixed offset timezones, or the name of timezone if not set.
def _is_pytz_zone(tz):
Checks if a zone is a pytz zone.
def _pytz_imported():

Detects whether or not pytz has been imported without importing pytz.

Copied from pytz_deprecation_shim with thanks to Paul Ganssle.

def template_localtime(value, use_tz=None):

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.

_PYTZ_IMPORTED: bool =

Undocumented

Value
False
_active =

Undocumented