simple.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:filters 作者: eflglobal 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号