本文整理汇总了Python中nldate.parser.parse函数的典型用法代码示例。如果您正苦于以下问题:Python parse函数的具体用法?Python parse怎么用?Python parse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parse函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_every_weekday
def test_every_weekday(self):
r = parse('every weekday', default=datetime(2011, 5, 10))
self.assertEqual(
r.between(datetime(2011, 5, 10), datetime(2011, 5, 20)),
[
datetime(2011, 5, 11, 0, 0),
datetime(2011, 5, 12, 0, 0),
datetime(2011, 5, 13, 0, 0),
datetime(2011, 5, 16, 0, 0),
datetime(2011, 5, 17, 0, 0),
datetime(2011, 5, 18, 0, 0),
datetime(2011, 5, 19, 0, 0)
]
)
r = parse('every wday', default=datetime(2011, 5, 10))
self.assertEqual(
r.between(datetime(2011, 5, 10), datetime(2011, 5, 20)),
[
datetime(2011, 5, 11, 0, 0),
datetime(2011, 5, 12, 0, 0),
datetime(2011, 5, 13, 0, 0),
datetime(2011, 5, 16, 0, 0),
datetime(2011, 5, 17, 0, 0),
datetime(2011, 5, 18, 0, 0),
datetime(2011, 5, 19, 0, 0)
]
)
示例2: testIncreasingCTime
def testIncreasingCTime(self):
# This test will check 200 different years, every month, every day,
# every hour, every minute, every second, and every weekday, using
# a delta of more or less 1 year, 1 month, 1 day, 1 minute and
# 1 second.
delta = timedelta(days=365 + 31 + 1, seconds=1 + 60 + 60 * 60)
dt = datetime(1900, 1, 1, 0, 0, 0, 0)
for i in range(200):
self.assertEqual(parse(dt.ctime()), dt)
dt += delta
示例3: testMicrosecondPrecisionErrorReturns
def testMicrosecondPrecisionErrorReturns(self):
# One more precision issue, discovered by Eric Brown. This should
# be the last one, as we're no longer using floating points.
data = [
100001, 100000, 99999, 99998,
10001, 10000, 9999, 9998,
1001, 1000, 999, 998,
101, 100, 99, 98
]
for ms in data:
dt = datetime(2008, 2, 27, 21, 26, 1, ms)
self.assertEquals(parse(dt.isoformat()), dt)
示例4: test_every_day_1pm
def test_every_day_1pm(self):
r = parse('every day at 1pm', default=datetime(2011, 5, 10))
self.assertEqual(
r.between(datetime(2011, 5, 10), datetime(2011, 5, 15)),
[
datetime(2011, 5, 10, 13, 0),
datetime(2011, 5, 11, 13, 0),
datetime(2011, 5, 12, 13, 0),
datetime(2011, 5, 13, 13, 0),
datetime(2011, 5, 14, 13, 0)
]
)
示例5: test_every_mon_fri_20_pm
def test_every_mon_fri_20_pm(self):
r = parse('every mon, fri at 20:00', default=datetime(2011, 5, 10))
self.assertEqual(
r.between(datetime(2011, 5, 10), datetime(2011, 6, 15)),
[
datetime(2011, 5, 13, 20, 0),
datetime(2011, 5, 16, 20, 0),
datetime(2011, 5, 20, 20, 0),
datetime(2011, 5, 23, 20, 0),
datetime(2011, 5, 27, 20, 0),
datetime(2011, 5, 30, 20, 0),
datetime(2011, 6, 3, 20, 0),
datetime(2011, 6, 6, 20, 0),
datetime(2011, 6, 10, 20, 0),
datetime(2011, 6, 13, 20, 0)
]
)
示例6: test_complex_timeframe
def test_complex_timeframe(self):
values = parse(
'every monday weekly from July 4 12h, 1974 to Oct 2 1974'
)
self.assertEqual(
list(values),
[
datetime(1974, 7, 8, 12, 0),
datetime(1974, 7, 15, 12, 0),
datetime(1974, 7, 22, 12, 0),
datetime(1974, 7, 29, 12, 0),
datetime(1974, 8, 5, 12, 0),
datetime(1974, 8, 12, 12, 0),
datetime(1974, 8, 19, 12, 0),
datetime(1974, 8, 26, 12, 0),
datetime(1974, 9, 2, 12, 0),
datetime(1974, 9, 9, 12, 0),
datetime(1974, 9, 16, 12, 0),
datetime(1974, 9, 23, 12, 0),
datetime(1974, 9, 30, 12, 0)
]
)
示例7: testRandomFormat32
def testRandomFormat32(self):
self.assertEqual(parse("01h02s", default=self.default),
datetime(2003, 9, 25, 1, 0, 2))
示例8: testRandomFormat30
def testRandomFormat30(self):
self.assertEqual(parse("01h02m03", default=self.default),
datetime(2003, 9, 25, 1, 2, 3))
示例9: testRandomFormat19
def testRandomFormat19(self):
self.assertEqual(parse("Mon Jan 2 04:24:27 1995"),
datetime(1995, 1, 2, 4, 24, 27))
示例10: test_every_day
def test_every_day(self):
r = parse('ev day', default=datetime(2003, 9, 9))
self.assertEqual(r.between(datetime(2003, 9, 10),
datetime(2003, 9, 15)),
[datetime(2003, 9, 11), datetime(2003, 9, 12),
datetime(2003, 9, 13), datetime(2003, 9, 14)])
示例11: testRandomFormat14
def testRandomFormat14(self):
self.assertEqual(parse("12h 01m02s am", default=self.default),
datetime(2003, 9, 25, 0, 1, 2))
示例12: testIncreasingISOFormat
def testIncreasingISOFormat(self):
delta = timedelta(days=365 + 31 + 1, seconds=1 + 60 + 60 * 60)
dt = datetime(1900, 1, 1, 0, 0, 0, 0)
for i in range(200):
self.assertEqual(parse(dt.isoformat()), dt)
dt += delta
示例13: testRandomFormat35
def testRandomFormat35(self):
self.assertEqual(parse("2004 10 Apr 11h30m", default=self.default),
datetime(2004, 4, 10, 11, 30))
示例14: testRandomFormat24
def testRandomFormat24(self):
self.assertEqual(parse("0:00 PM, PST", default=self.default,
ignoretz=True),
datetime(2003, 9, 25, 12, 0))
示例15: testRandomFormat23
def testRandomFormat23(self):
self.assertEqual(parse("950404 122212"),
datetime(1995, 4, 4, 12, 22, 12))