當前位置: 首頁>>代碼示例>>Python>>正文


Python dateutil.tz方法代碼示例

本文整理匯總了Python中dateutil.tz方法的典型用法代碼示例。如果您正苦於以下問題:Python dateutil.tz方法的具體用法?Python dateutil.tz怎麽用?Python dateutil.tz使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在dateutil的用法示例。


在下文中一共展示了dateutil.tz方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: testImportedModules

# 需要導入模塊: import dateutil [as 別名]
# 或者: from dateutil import tz [as 別名]
def testImportedModules(self):
        import dateutil.easter
        import dateutil.parser
        import dateutil.relativedelta
        import dateutil.rrule
        import dateutil.tz
        import dateutil.utils
        import dateutil.zoneinfo

        self.assertEquals(dateutil.easter, new_locals.pop("easter"))
        self.assertEquals(dateutil.parser, new_locals.pop("parser"))
        self.assertEquals(dateutil.relativedelta, new_locals.pop("relativedelta"))
        self.assertEquals(dateutil.rrule, new_locals.pop("rrule"))
        self.assertEquals(dateutil.tz, new_locals.pop("tz"))
        self.assertEquals(dateutil.utils, new_locals.pop("utils"))
        self.assertEquals(dateutil.zoneinfo, new_locals.pop("zoneinfo"))

        self.assertFalse(new_locals) 
開發者ID:MediaBrowser,項目名稱:plugin.video.emby,代碼行數:20,代碼來源:test_import_star.py

示例2: testTzAll

# 需要導入模塊: import dateutil [as 別名]
# 或者: from dateutil import tz [as 別名]
def testTzAll(self):
        from dateutil.tz import tzutc
        from dateutil.tz import tzoffset
        from dateutil.tz import tzlocal
        from dateutil.tz import tzfile
        from dateutil.tz import tzrange
        from dateutil.tz import tzstr
        from dateutil.tz import tzical
        from dateutil.tz import gettz
        from dateutil.tz import tzwin
        from dateutil.tz import tzwinlocal
        from dateutil.tz import UTC
        from dateutil.tz import datetime_ambiguous
        from dateutil.tz import datetime_exists
        from dateutil.tz import resolve_imaginary

        tz_all = ["tzutc", "tzoffset", "tzlocal", "tzfile", "tzrange",
                  "tzstr", "tzical", "gettz", "datetime_ambiguous",
                  "datetime_exists", "resolve_imaginary", "UTC"]

        tz_all += ["tzwin", "tzwinlocal"] if sys.platform.startswith("win") else []
        lvars = locals()

        for var in tz_all:
            self.assertIsNot(lvars[var], None) 
開發者ID:MediaBrowser,項目名稱:plugin.video.emby,代碼行數:27,代碼來源:test_imports.py

示例3: test_dti_tz_localize_nonexistent_raise_coerce

# 需要導入模塊: import dateutil [as 別名]
# 或者: from dateutil import tz [as 別名]
def test_dti_tz_localize_nonexistent_raise_coerce(self):
        # GH#13057
        times = ['2015-03-08 01:00', '2015-03-08 02:00', '2015-03-08 03:00']
        index = DatetimeIndex(times)
        tz = 'US/Eastern'
        with pytest.raises(pytz.NonExistentTimeError):
            index.tz_localize(tz=tz)

        with pytest.raises(pytz.NonExistentTimeError):
            with tm.assert_produces_warning(FutureWarning):
                index.tz_localize(tz=tz, errors='raise')

        with tm.assert_produces_warning(FutureWarning,
                                        clear=FutureWarning,
                                        check_stacklevel=False):
            result = index.tz_localize(tz=tz, errors='coerce')
        test_times = ['2015-03-08 01:00-05:00', 'NaT',
                      '2015-03-08 03:00-04:00']
        dti = to_datetime(test_times, utc=True)
        expected = dti.tz_convert('US/Eastern')
        tm.assert_index_equal(result, expected) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:23,代碼來源:test_timezones.py

示例4: test_dti_tz_localize_ambiguous_infer

# 需要導入模塊: import dateutil [as 別名]
# 或者: from dateutil import tz [as 別名]
def test_dti_tz_localize_ambiguous_infer(self, tz):
        # November 6, 2011, fall back, repeat 2 AM hour
        # With no repeated hours, we cannot infer the transition
        dr = date_range(datetime(2011, 11, 6, 0), periods=5,
                        freq=pd.offsets.Hour())
        with pytest.raises(pytz.AmbiguousTimeError):
            dr.tz_localize(tz)

        # With repeated hours, we can infer the transition
        dr = date_range(datetime(2011, 11, 6, 0), periods=5,
                        freq=pd.offsets.Hour(), tz=tz)
        times = ['11/06/2011 00:00', '11/06/2011 01:00', '11/06/2011 01:00',
                 '11/06/2011 02:00', '11/06/2011 03:00']
        di = DatetimeIndex(times)
        localized = di.tz_localize(tz, ambiguous='infer')
        tm.assert_index_equal(dr, localized)
        tm.assert_index_equal(dr, DatetimeIndex(times, tz=tz,
                                                ambiguous='infer'))

        # When there is no dst transition, nothing special happens
        dr = date_range(datetime(2011, 6, 1, 0), periods=10,
                        freq=pd.offsets.Hour())
        localized = dr.tz_localize(tz)
        localized_infer = dr.tz_localize(tz, ambiguous='infer')
        tm.assert_index_equal(localized, localized_infer) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:27,代碼來源:test_timezones.py

示例5: test_dti_tz_localize_ambiguous_times

# 需要導入模塊: import dateutil [as 別名]
# 或者: from dateutil import tz [as 別名]
def test_dti_tz_localize_ambiguous_times(self, tz):
        # March 13, 2011, spring forward, skip from 2 AM to 3 AM
        dr = date_range(datetime(2011, 3, 13, 1, 30), periods=3,
                        freq=pd.offsets.Hour())
        with pytest.raises(pytz.NonExistentTimeError):
            dr.tz_localize(tz)

        # after dst transition, it works
        dr = date_range(datetime(2011, 3, 13, 3, 30), periods=3,
                        freq=pd.offsets.Hour(), tz=tz)

        # November 6, 2011, fall back, repeat 2 AM hour
        dr = date_range(datetime(2011, 11, 6, 1, 30), periods=3,
                        freq=pd.offsets.Hour())
        with pytest.raises(pytz.AmbiguousTimeError):
            dr.tz_localize(tz)

        # UTC is OK
        dr = date_range(datetime(2011, 3, 13), periods=48,
                        freq=pd.offsets.Minute(30), tz=pytz.utc) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:22,代碼來源:test_timezones.py

示例6: test_dti_tz_localize

# 需要導入模塊: import dateutil [as 別名]
# 或者: from dateutil import tz [as 別名]
def test_dti_tz_localize(self, prefix):
        tzstr = prefix + 'US/Eastern'
        dti = pd.date_range(start='1/1/2005', end='1/1/2005 0:00:30.256',
                            freq='L')
        dti2 = dti.tz_localize(tzstr)

        dti_utc = pd.date_range(start='1/1/2005 05:00',
                                end='1/1/2005 5:00:30.256', freq='L', tz='utc')

        tm.assert_numpy_array_equal(dti2.values, dti_utc.values)

        dti3 = dti2.tz_convert(prefix + 'US/Pacific')
        tm.assert_numpy_array_equal(dti3.values, dti_utc.values)

        dti = pd.date_range(start='11/6/2011 1:59', end='11/6/2011 2:00',
                            freq='L')
        with pytest.raises(pytz.AmbiguousTimeError):
            dti.tz_localize(tzstr)

        dti = pd.date_range(start='3/13/2011 1:59', end='3/13/2011 2:00',
                            freq='L')
        with pytest.raises(pytz.NonExistentTimeError):
            dti.tz_localize(tzstr) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:25,代碼來源:test_timezones.py

示例7: test_dti_tz_localize_utc_conversion

# 需要導入模塊: import dateutil [as 別名]
# 或者: from dateutil import tz [as 別名]
def test_dti_tz_localize_utc_conversion(self, tz):
        # Localizing to time zone should:
        #  1) check for DST ambiguities
        #  2) convert to UTC

        rng = date_range('3/10/2012', '3/11/2012', freq='30T')

        converted = rng.tz_localize(tz)
        expected_naive = rng + pd.offsets.Hour(5)
        tm.assert_numpy_array_equal(converted.asi8, expected_naive.asi8)

        # DST ambiguity, this should fail
        rng = date_range('3/11/2012', '3/12/2012', freq='30T')
        # Is this really how it should fail??
        with pytest.raises(pytz.NonExistentTimeError):
            rng.tz_localize(tz) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:18,代碼來源:test_timezones.py

示例8: test_normalize_tz_local

# 需要導入模塊: import dateutil [as 別名]
# 或者: from dateutil import tz [as 別名]
def test_normalize_tz_local(self, timezone):
        # GH#13459
        with tm.set_timezone(timezone):
            rng = date_range('1/1/2000 9:30', periods=10, freq='D',
                             tz=tzlocal())

            result = rng.normalize()
            expected = date_range('1/1/2000', periods=10, freq='D',
                                  tz=tzlocal())
            tm.assert_index_equal(result, expected)

            assert result.is_normalized
            assert not rng.is_normalized

    # ------------------------------------------------------------
    # DatetimeIndex.__new__ 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:18,代碼來源:test_timezones.py

示例9: test_dti_tz_constructors

# 需要導入模塊: import dateutil [as 別名]
# 或者: from dateutil import tz [as 別名]
def test_dti_tz_constructors(self, tzstr):
        """ Test different DatetimeIndex constructions with timezone
        Follow-up of GH#4229
        """

        arr = ['11/10/2005 08:00:00', '11/10/2005 09:00:00']

        idx1 = to_datetime(arr).tz_localize(tzstr)
        idx2 = pd.date_range(start="2005-11-10 08:00:00", freq='H', periods=2,
                             tz=tzstr)
        idx3 = DatetimeIndex(arr, tz=tzstr)
        idx4 = DatetimeIndex(np.array(arr), tz=tzstr)

        for other in [idx2, idx3, idx4]:
            tm.assert_index_equal(idx1, other)

    # -------------------------------------------------------------
    # Unsorted 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:20,代碼來源:test_timezones.py

示例10: test_drop_dst_boundary

# 需要導入模塊: import dateutil [as 別名]
# 或者: from dateutil import tz [as 別名]
def test_drop_dst_boundary(self):
        # see gh-18031
        tz = "Europe/Brussels"
        freq = "15min"

        start = pd.Timestamp("201710290100", tz=tz)
        end = pd.Timestamp("201710290300", tz=tz)
        index = pd.date_range(start=start, end=end, freq=freq)

        expected = DatetimeIndex(["201710290115", "201710290130",
                                  "201710290145", "201710290200",
                                  "201710290215", "201710290230",
                                  "201710290245", "201710290200",
                                  "201710290215", "201710290230",
                                  "201710290245", "201710290300"],
                                 tz=tz, freq=freq,
                                 ambiguous=[True, True, True, True,
                                            True, True, True, False,
                                            False, False, False, False])
        result = index.drop(index[0])
        tm.assert_index_equal(result, expected) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:23,代碼來源:test_timezones.py

示例11: test_dti_astype_asobject_tzinfos

# 需要導入模塊: import dateutil [as 別名]
# 或者: from dateutil import tz [as 別名]
def test_dti_astype_asobject_tzinfos(self, tzstr):
        # GH#1345

        # dates around a dst transition
        rng = date_range('2/13/2010', '5/6/2010', tz=tzstr)

        objs = rng.astype(object)
        for i, x in enumerate(objs):
            exval = rng[i]
            assert x == exval
            assert x.tzinfo == exval.tzinfo

        objs = rng.astype(object)
        for i, x in enumerate(objs):
            exval = rng[i]
            assert x == exval
            assert x.tzinfo == exval.tzinfo 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:19,代碼來源:test_timezones.py

示例12: test_utc_box_timestamp_and_localize

# 需要導入模塊: import dateutil [as 別名]
# 或者: from dateutil import tz [as 別名]
def test_utc_box_timestamp_and_localize(self, tzstr):
        tz = timezones.maybe_get_tz(tzstr)

        rng = date_range('3/11/2012', '3/12/2012', freq='H', tz='utc')
        rng_eastern = rng.tz_convert(tzstr)

        expected = rng[-1].astimezone(tz)

        stamp = rng_eastern[-1]
        assert stamp == expected
        assert stamp.tzinfo == expected.tzinfo

        # right tzinfo
        rng = date_range('3/13/2012', '3/14/2012', freq='H', tz='utc')
        rng_eastern = rng.tz_convert(tzstr)
        # test not valid for dateutil timezones.
        # assert 'EDT' in repr(rng_eastern[0].tzinfo)
        assert ('EDT' in repr(rng_eastern[0].tzinfo) or
                'tzfile' in repr(rng_eastern[0].tzinfo)) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:21,代碼來源:test_timezones.py

示例13: test_astype_datetime64

# 需要導入模塊: import dateutil [as 別名]
# 或者: from dateutil import tz [as 別名]
def test_astype_datetime64(self):
        # GH 13149, GH 13209
        idx = DatetimeIndex(['2016-05-16', 'NaT', NaT, np.NaN])

        result = idx.astype('datetime64[ns]')
        tm.assert_index_equal(result, idx)
        assert result is not idx

        result = idx.astype('datetime64[ns]', copy=False)
        tm.assert_index_equal(result, idx)
        assert result is idx

        idx_tz = DatetimeIndex(['2016-05-16', 'NaT', NaT, np.NaN], tz='EST')
        result = idx_tz.astype('datetime64[ns]')
        expected = DatetimeIndex(['2016-05-16 05:00:00', 'NaT', 'NaT', 'NaT'],
                                 dtype='datetime64[ns]')
        tm.assert_index_equal(result, expected) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:19,代碼來源:test_astype.py

示例14: test_index_convert_to_datetime_array

# 需要導入模塊: import dateutil [as 別名]
# 或者: from dateutil import tz [as 別名]
def test_index_convert_to_datetime_array(self):
        def _check_rng(rng):
            converted = rng.to_pydatetime()
            assert isinstance(converted, np.ndarray)
            for x, stamp in zip(converted, rng):
                assert isinstance(x, datetime)
                assert x == stamp.to_pydatetime()
                assert x.tzinfo == stamp.tzinfo

        rng = date_range('20090415', '20090519')
        rng_eastern = date_range('20090415', '20090519', tz='US/Eastern')
        rng_utc = date_range('20090415', '20090519', tz='utc')

        _check_rng(rng)
        _check_rng(rng_eastern)
        _check_rng(rng_utc) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:18,代碼來源:test_astype.py

示例15: test_index_convert_to_datetime_array_explicit_pytz

# 需要導入模塊: import dateutil [as 別名]
# 或者: from dateutil import tz [as 別名]
def test_index_convert_to_datetime_array_explicit_pytz(self):
        def _check_rng(rng):
            converted = rng.to_pydatetime()
            assert isinstance(converted, np.ndarray)
            for x, stamp in zip(converted, rng):
                assert isinstance(x, datetime)
                assert x == stamp.to_pydatetime()
                assert x.tzinfo == stamp.tzinfo

        rng = date_range('20090415', '20090519')
        rng_eastern = date_range('20090415', '20090519',
                                 tz=pytz.timezone('US/Eastern'))
        rng_utc = date_range('20090415', '20090519', tz=pytz.utc)

        _check_rng(rng)
        _check_rng(rng_eastern)
        _check_rng(rng_utc) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:19,代碼來源:test_astype.py


注:本文中的dateutil.tz方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。