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


Python _strptime._strptime方法代码示例

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


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

示例1: test_date_time

# 需要导入模块: import _strptime [as 别名]
# 或者: from _strptime import _strptime [as 别名]
def test_date_time(self):
        # Check that LC_date_time, LC_date, and LC_time are correct
        # the magic date is used so as to not have issues with %c when day of
        #  the month is a single digit and has a leading space.  This is not an
        #  issue since strptime still parses it correctly.  The problem is
        #  testing these directives for correctness by comparing strftime
        #  output.
        magic_date = (1999, 3, 17, 22, 44, 55, 2, 76, 0)
        strftime_output = time.strftime("%c", magic_date)
        self.assertEqual(time.strftime(self.LT_ins.LC_date_time, magic_date),
                         strftime_output, "LC_date_time incorrect")
        strftime_output = time.strftime("%x", magic_date)
        self.assertEqual(time.strftime(self.LT_ins.LC_date, magic_date),
                         strftime_output, "LC_date incorrect")
        strftime_output = time.strftime("%X", magic_date)
        self.assertEqual(time.strftime(self.LT_ins.LC_time, magic_date),
                         strftime_output, "LC_time incorrect")
        LT = _strptime.LocaleTime()
        LT.am_pm = ('', '')
        self.assertTrue(LT.LC_time, "LocaleTime's LC directives cannot handle "
                                    "empty strings") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:23,代码来源:test_strptime.py

示例2: test_timezone

# 需要导入模块: import _strptime [as 别名]
# 或者: from _strptime import _strptime [as 别名]
def test_timezone(self):
        # Test timezone directives.
        # When gmtime() is used with %Z, entire result of strftime() is empty.
        # Check for equal timezone names deals with bad locale info when this
        # occurs; first found in FreeBSD 4.4.
        strp_output = _strptime._strptime_time("UTC", "%Z")
        self.assertEqual(strp_output.tm_isdst, 0)
        strp_output = _strptime._strptime_time("GMT", "%Z")
        self.assertEqual(strp_output.tm_isdst, 0)
        time_tuple = time.localtime()
        strf_output = time.strftime("%Z")  #UTC does not have a timezone
        strp_output = _strptime._strptime_time(strf_output, "%Z")
        locale_time = _strptime.LocaleTime()
        if time.tzname[0] != time.tzname[1] or not time.daylight:
            self.assertTrue(strp_output[8] == time_tuple[8],
                            "timezone check failed; '%s' -> %s != %s" %
                             (strf_output, strp_output[8], time_tuple[8]))
        else:
            self.assertTrue(strp_output[8] == -1,
                            "LocaleTime().timezone has duplicate values and "
                             "time.daylight but timezone value not set to -1") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:23,代码来源:test_strptime.py

示例3: test_bad_timezone

# 需要导入模块: import _strptime [as 别名]
# 或者: from _strptime import _strptime [as 别名]
def test_bad_timezone(self):
        # Explicitly test possibility of bad timezone;
        # when time.tzname[0] == time.tzname[1] and time.daylight
        tz_name = time.tzname[0]
        if tz_name.upper() in ("UTC", "GMT"):
            self.skipTest('need non-UTC/GMT timezone')

        with support.swap_attr(time, 'tzname', (tz_name, tz_name)), \
             support.swap_attr(time, 'daylight', 1), \
             support.swap_attr(time, 'tzset', lambda: None):
            time.tzname = (tz_name, tz_name)
            time.daylight = 1
            tz_value = _strptime._strptime_time(tz_name, "%Z")[8]
            self.assertEqual(tz_value, -1,
                    "%s lead to a timezone value of %s instead of -1 when "
                    "time.daylight set to %s and passing in %s" %
                    (time.tzname, tz_value, time.daylight, tz_name)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:19,代码来源:test_strptime.py

示例4: test_TimeRE_recreation_timezone

# 需要导入模块: import _strptime [as 别名]
# 或者: from _strptime import _strptime [as 别名]
def test_TimeRE_recreation_timezone(self):
        # The TimeRE instance should be recreated upon changing the timezone.
        oldtzname = time.tzname
        tm = _strptime._strptime_time(time.tzname[0], '%Z')
        self.assertEqual(tm.tm_isdst, 0)
        tm = _strptime._strptime_time(time.tzname[1], '%Z')
        self.assertEqual(tm.tm_isdst, 1)
        # Get id of current cache object.
        first_time_re = _strptime._TimeRE_cache
        # Change the timezone and force a recreation of the cache.
        os.environ['TZ'] = 'EST+05EDT,M3.2.0,M11.1.0'
        time.tzset()
        tm = _strptime._strptime_time(time.tzname[0], '%Z')
        self.assertEqual(tm.tm_isdst, 0)
        tm = _strptime._strptime_time(time.tzname[1], '%Z')
        self.assertEqual(tm.tm_isdst, 1)
        # Get the new cache object's id.
        second_time_re = _strptime._TimeRE_cache
        # They should not be equal.
        self.assertIsNot(first_time_re, second_time_re)
        # Make sure old names no longer accepted.
        with self.assertRaises(ValueError):
            _strptime._strptime_time(oldtzname[0], '%Z')
        with self.assertRaises(ValueError):
            _strptime._strptime_time(oldtzname[1], '%Z') 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:27,代码来源:test_strptime.py

示例5: test_bad_timezone

# 需要导入模块: import _strptime [as 别名]
# 或者: from _strptime import _strptime [as 别名]
def test_bad_timezone(self):
        # Explicitly test possibility of bad timezone;
        # when time.tzname[0] == time.tzname[1] and time.daylight
        tz_name = time.tzname[0]
        if tz_name.upper() in ("UTC", "GMT"):
            return
        try:
            original_tzname = time.tzname
            original_daylight = time.daylight
            time.tzname = (tz_name, tz_name)
            time.daylight = 1
            tz_value = _strptime._strptime_time(tz_name, "%Z")[8]
            self.assertEqual(tz_value, -1,
                    "%s lead to a timezone value of %s instead of -1 when "
                    "time.daylight set to %s and passing in %s" %
                    (time.tzname, tz_value, time.daylight, tz_name))
        finally:
            time.tzname = original_tzname
            time.daylight = original_daylight 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:21,代码来源:test_strptime.py

示例6: test_bad_timezone

# 需要导入模块: import _strptime [as 别名]
# 或者: from _strptime import _strptime [as 别名]
def test_bad_timezone(self):
        # Explicitly test possibility of bad timezone;
        # when time.tzname[0] == time.tzname[1] and time.daylight
        tz_name = time.tzname[0]
        if tz_name.upper() in ("UTC", "GMT"):
            self.skipTest('need non-UTC/GMT timezone')
        try:
            original_tzname = time.tzname
            original_daylight = time.daylight
            time.tzname = (tz_name, tz_name)
            time.daylight = 1
            tz_value = _strptime._strptime_time(tz_name, "%Z")[8]
            self.assertEqual(tz_value, -1,
                    "%s lead to a timezone value of %s instead of -1 when "
                    "time.daylight set to %s and passing in %s" %
                    (time.tzname, tz_value, time.daylight, tz_name))
        finally:
            time.tzname = original_tzname
            time.daylight = original_daylight 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:21,代码来源:test_strptime.py

示例7: test_basic

# 需要导入模块: import _strptime [as 别名]
# 或者: from _strptime import _strptime [as 别名]
def test_basic(self):
        self.assertEqual(_strptime._getlang(), locale.getlocale(locale.LC_TIME)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:4,代码来源:test_strptime.py

示例8: setUp

# 需要导入模块: import _strptime [as 别名]
# 或者: from _strptime import _strptime [as 别名]
def setUp(self):
        """Create time tuple based on current time."""
        self.time_tuple = time.localtime()
        self.LT_ins = _strptime.LocaleTime() 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:6,代码来源:test_strptime.py

示例9: test_lang

# 需要导入模块: import _strptime [as 别名]
# 或者: from _strptime import _strptime [as 别名]
def test_lang(self):
        # Make sure lang is set to what _getlang() returns
        # Assuming locale has not changed between now and when self.LT_ins was created
        self.assertEqual(self.LT_ins.lang, _strptime._getlang()) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:6,代码来源:test_strptime.py

示例10: test_locale_data_w_regex_metacharacters

# 需要导入模块: import _strptime [as 别名]
# 或者: from _strptime import _strptime [as 别名]
def test_locale_data_w_regex_metacharacters(self):
        # Check that if locale data contains regex metacharacters they are
        # escaped properly.
        # Discovered by bug #1039270 .
        locale_time = _strptime.LocaleTime()
        locale_time.timezone = (frozenset(("utc", "gmt",
                                            "Tokyo (standard time)")),
                                frozenset("Tokyo (daylight time)"))
        time_re = _strptime.TimeRE(locale_time)
        self.assertTrue(time_re.compile("%Z").match("Tokyo (standard time)"),
                        "locale data that contains regex metacharacters is not"
                        " properly escaped") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:14,代码来源:test_strptime.py

示例11: test_ValueError

# 需要导入模块: import _strptime [as 别名]
# 或者: from _strptime import _strptime [as 别名]
def test_ValueError(self):
        # Make sure ValueError is raised when match fails or format is bad
        self.assertRaises(ValueError, _strptime._strptime_time, data_string="%d",
                          format="%A")
        for bad_format in ("%", "% ", "%e"):
            try:
                _strptime._strptime_time("2005", bad_format)
            except ValueError:
                continue
            except Exception, err:
                self.fail("'%s' raised %s, not ValueError" %
                            (bad_format, err.__class__.__name__))
            else:
                self.fail("'%s' did not raise ValueError" % bad_format) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:16,代码来源:test_strptime.py

示例12: test_unconverteddata

# 需要导入模块: import _strptime [as 别名]
# 或者: from _strptime import _strptime [as 别名]
def test_unconverteddata(self):
        # Check ValueError is raised when there is unconverted data
        self.assertRaises(ValueError, _strptime._strptime_time, "10 12", "%m") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:5,代码来源:test_strptime.py

示例13: helper

# 需要导入模块: import _strptime [as 别名]
# 或者: from _strptime import _strptime [as 别名]
def helper(self, directive, position):
        """Helper fxn in testing."""
        strf_output = time.strftime("%" + directive, self.time_tuple)
        strp_output = _strptime._strptime_time(strf_output, "%" + directive)
        self.assertTrue(strp_output[position] == self.time_tuple[position],
                        "testing of '%s' directive failed; '%s' -> %s != %s" %
                         (directive, strf_output, strp_output[position],
                          self.time_tuple[position])) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:10,代码来源:test_strptime.py

示例14: test_year

# 需要导入模块: import _strptime [as 别名]
# 或者: from _strptime import _strptime [as 别名]
def test_year(self):
        # Test that the year is handled properly
        for directive in ('y', 'Y'):
            self.helper(directive, 0)
        # Must also make sure %y values are correct for bounds set by Open Group
        for century, bounds in ((1900, ('69', '99')), (2000, ('00', '68'))):
            for bound in bounds:
                strp_output = _strptime._strptime_time(bound, '%y')
                expected_result = century + int(bound)
                self.assertTrue(strp_output[0] == expected_result,
                                "'y' test failed; passed in '%s' "
                                "and returned '%s'" % (bound, strp_output[0])) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:14,代码来源:test_strptime.py

示例15: test_fraction

# 需要导入模块: import _strptime [as 别名]
# 或者: from _strptime import _strptime [as 别名]
def test_fraction(self):
        # Test microseconds
        import datetime
        d = datetime.datetime(2012, 12, 20, 12, 34, 56, 78987)
        tup, frac = _strptime._strptime(str(d), format="%Y-%m-%d %H:%M:%S.%f")
        self.assertEqual(frac, d.microsecond) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:8,代码来源:test_strptime.py


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