def __init__(self, timezone=None, naive=False):
# type: (Optional[Union[tzinfo, int, float]], bool) -> None
"""
:param timezone:
Specifies the timezone to use when the *incoming* value is
a naive timestamp. Has no effect on timezone-aware
timestamps.
IMPORTANT: The result is always converted to UTC,
regardless of the value of the ``timezone`` param!
You can provide an int/float here, which is the offset from
UTC in hours (e.g., 5 = UTC+5).
:param naive:
If True, the filter will *return* naive datetime objects
(sans tzinfo). This is useful e.g., for datetimes that
will be stored in a database that doesn't understand aware
timestamps.
IMPORTANT: Incoming values are still converted to UTC
before stripping tzinfo!
"""
super(Datetime, self).__init__()
if not isinstance(timezone, tzinfo):
if timezone in [0, None]:
timezone = utc
else:
# Assume that we got an int/float instead.
timezone = tzoffset(
name = 'UTC{offset:+}'.format(offset=timezone),
offset = float(timezone) * 3600.0,
)
self.timezone = timezone
self.naive = naive
评论列表
文章目录