当前位置: 首页>>代码示例>>Python>>正文


Python pytz.tzinfo方法代码示例

本文整理汇总了Python中pytz.tzinfo方法的典型用法代码示例。如果您正苦于以下问题:Python pytz.tzinfo方法的具体用法?Python pytz.tzinfo怎么用?Python pytz.tzinfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pytz的用法示例。


在下文中一共展示了pytz.tzinfo方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_arithmetic

# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import tzinfo [as 别名]
def test_arithmetic(self):
        utc_dt = self.transition_time

        for days in range(-420, 720, 20):
            delta = timedelta(days=days)

            # Make sure we can get back where we started
            dt = utc_dt.astimezone(self.tzinfo)
            dt2 = dt + delta
            dt2 = dt2 - delta
            self.assertEqual(dt, dt2)

            # Make sure arithmetic crossing DST boundaries ends
            # up in the correct timezone after normalization
            utc_plus_delta = (utc_dt + delta).astimezone(self.tzinfo)
            local_plus_delta = self.tzinfo.normalize(dt + delta)
            self.assertEqual(
                    prettydt(utc_plus_delta),
                    prettydt(local_plus_delta),
                    'Incorrect result for delta==%d days.  Wanted %r. Got %r'%(
                        days,
                        prettydt(utc_plus_delta),
                        prettydt(local_plus_delta),
                        )
                    ) 
开发者ID:Schibum,项目名称:sndlatr,代码行数:27,代码来源:test_tzinfo.py

示例2: test_fromutc

# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import tzinfo [as 别名]
def test_fromutc(self):
        # naive datetime.
        dt1 = datetime(2011, 10, 31)

        # localized datetime, same timezone.
        dt2 = self.tz.localize(dt1)

        # Both should give the same results. Note that the standard
        # Python tzinfo.fromutc() only supports the second.
        for dt in [dt1, dt2]:
            loc_dt = self.tz.fromutc(dt)
            loc_dt2 = pytz.utc.localize(dt1).astimezone(self.tz)
            self.assertEqual(loc_dt, loc_dt2)

        # localized datetime, different timezone.
        new_tz = pytz.timezone('Europe/Paris')
        self.assertTrue(self.tz is not new_tz)
        dt3 = new_tz.localize(dt1)
        self.assertRaises(ValueError, self.tz.fromutc, dt3) 
开发者ID:Schibum,项目名称:sndlatr,代码行数:21,代码来源:test_tzinfo.py

示例3: fromutc

# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import tzinfo [as 别名]
def fromutc(self, dt):
        if dt.tzinfo is None:
            return self.localize(dt)
        return super(utc.__class__, self).fromutc(dt) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:6,代码来源:__init__.py

示例4: localize

# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import tzinfo [as 别名]
def localize(self, dt, is_dst=False):
        '''Convert naive time to local time'''
        if dt.tzinfo is not None:
            raise ValueError('Not naive datetime (tzinfo is already set)')
        return dt.replace(tzinfo=self) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:7,代码来源:__init__.py

示例5: normalize

# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import tzinfo [as 别名]
def normalize(self, dt, is_dst=False):
        '''Correct the timezone information on the given datetime'''
        if dt.tzinfo is self:
            return dt
        if dt.tzinfo is None:
            raise ValueError('Naive time - no tzinfo set')
        return dt.astimezone(self) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:9,代码来源:__init__.py

示例6: _UTC

# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import tzinfo [as 别名]
def _UTC():
    """Factory function for utc unpickling.

    Makes sure that unpickling a utc instance always returns the same
    module global.

    These examples belong in the UTC class above, but it is obscured; or in
    the README.txt, but we are not depending on Python 2.4 so integrating
    the README.txt examples with the unit tests is not trivial.

    >>> import datetime, pickle
    >>> dt = datetime.datetime(2005, 3, 1, 14, 13, 21, tzinfo=utc)
    >>> naive = dt.replace(tzinfo=None)
    >>> p = pickle.dumps(dt, 1)
    >>> naive_p = pickle.dumps(naive, 1)
    >>> len(p) - len(naive_p)
    17
    >>> new = pickle.loads(p)
    >>> new == dt
    True
    >>> new is dt
    False
    >>> new.tzinfo is dt.tzinfo
    True
    >>> utc is UTC is timezone('UTC')
    True
    >>> utc is timezone('GMT')
    False
    """
    return utc 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:32,代码来源:__init__.py

示例7: _p

# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import tzinfo [as 别名]
def _p(*args):
    """Factory function for unpickling pytz tzinfo instances.

    Just a wrapper around tzinfo.unpickler to save a few bytes in each pickle
    by shortening the path.
    """
    return unpickler(*args) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:9,代码来源:__init__.py


注:本文中的pytz.tzinfo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。