本文整理汇总了Python中pywikibot.Timestamp.utcnow方法的典型用法代码示例。如果您正苦于以下问题:Python Timestamp.utcnow方法的具体用法?Python Timestamp.utcnow怎么用?Python Timestamp.utcnow使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pywikibot.Timestamp
的用法示例。
在下文中一共展示了Timestamp.utcnow方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_sub_timedate
# 需要导入模块: from pywikibot import Timestamp [as 别名]
# 或者: from pywikibot.Timestamp import utcnow [as 别名]
def test_sub_timedate(self):
"""Test subtracting two timestamps."""
t1 = Timestamp.utcnow()
t2 = t1 - datetime.timedelta(days=1)
td = t1 - t2
self.assertIsInstance(td, datetime.timedelta)
self.assertEqual(t2 + td, t1)
示例2: test_sub_timedelta
# 需要导入模块: from pywikibot import Timestamp [as 别名]
# 或者: from pywikibot.Timestamp import utcnow [as 别名]
def test_sub_timedelta(self):
t1 = T.utcnow()
t2 = t1 - datetime.timedelta(days=1)
if t1.month != t2.month:
self.assertEqual(calendar.monthrange(t2.year, t2.month)[1], t2.day)
else:
self.assertEqual(t1.day - 1, t2.day)
self.assertIsInstance(t2, T)
示例3: test_add_timedelta
# 需要导入模块: from pywikibot import Timestamp [as 别名]
# 或者: from pywikibot.Timestamp import utcnow [as 别名]
def test_add_timedelta(self):
t1 = T.utcnow()
t2 = t1 + datetime.timedelta(days=1)
if t1.month != t2.month:
self.assertEqual(1, t2.day)
else:
self.assertEqual(t1.day + 1, t2.day)
self.assertIsInstance(t2, T)
示例4: test_sub_timedelta
# 需要导入模块: from pywikibot import Timestamp [as 别名]
# 或者: from pywikibot.Timestamp import utcnow [as 别名]
def test_sub_timedelta(self):
"""Test substracting a timedelta from a Timestamp."""
t1 = Timestamp.utcnow()
t2 = t1 - datetime.timedelta(days=1)
if t1.month != t2.month:
self.assertEqual(calendar.monthrange(t2.year, t2.month)[1], t2.day)
else:
self.assertEqual(t1.day - 1, t2.day)
self.assertIsInstance(t2, Timestamp)
示例5: test_add_timedelta
# 需要导入模块: from pywikibot import Timestamp [as 别名]
# 或者: from pywikibot.Timestamp import utcnow [as 别名]
def test_add_timedelta(self):
"""Test addin a timedelta to a Timestamp."""
t1 = Timestamp.utcnow()
t2 = t1 + datetime.timedelta(days=1)
if t1.month != t2.month:
self.assertEqual(1, t2.day)
else:
self.assertEqual(t1.day + 1, t2.day)
self.assertIsInstance(t2, Timestamp)
示例6: test_instantiate_from_instance
# 需要导入模块: from pywikibot import Timestamp [as 别名]
# 或者: from pywikibot.Timestamp import utcnow [as 别名]
def test_instantiate_from_instance(self):
"""Test passing instance to factory methods works."""
t1 = Timestamp.utcnow()
self.assertIsNot(t1, Timestamp.fromISOformat(t1))
self.assertEqual(t1, Timestamp.fromISOformat(t1))
self.assertIsInstance(Timestamp.fromISOformat(t1), Timestamp)
self.assertIsNot(t1, Timestamp.fromtimestampformat(t1))
self.assertEqual(t1, Timestamp.fromtimestampformat(t1))
self.assertIsInstance(Timestamp.fromtimestampformat(t1), Timestamp)
示例7: test_mediawiki_format
# 需要导入模块: from pywikibot import Timestamp [as 别名]
# 或者: from pywikibot.Timestamp import utcnow [as 别名]
def test_mediawiki_format(self):
t1 = T.utcnow()
ts1 = t1.totimestampformat()
t2 = T.fromtimestampformat(ts1)
ts2 = t2.totimestampformat()
# MediaWiki timestamp format doesn't include microseconds
self.assertNotEqual(t1, t2)
t1 = t1.replace(microsecond=0)
self.assertEqual(t1, t2)
self.assertEqual(ts1, ts2)
示例8: test_iso_format
# 需要导入模块: from pywikibot import Timestamp [as 别名]
# 或者: from pywikibot.Timestamp import utcnow [as 别名]
def test_iso_format(self):
t1 = T.utcnow()
ts1 = t1.toISOformat()
t2 = T.fromISOformat(ts1)
ts2 = t2.toISOformat()
# MediaWiki ISO format doesn't include microseconds
self.assertNotEqual(t1, t2)
t1 = t1.replace(microsecond=0)
self.assertEqual(t1, t2)
self.assertEqual(ts1, ts2)
示例9: test_iso_format
# 需要导入模块: from pywikibot import Timestamp [as 别名]
# 或者: from pywikibot.Timestamp import utcnow [as 别名]
def test_iso_format(self):
"""Test conversion from and to ISO format."""
t1 = Timestamp.utcnow()
ts1 = t1.isoformat()
t2 = Timestamp.fromISOformat(ts1)
ts2 = t2.isoformat()
# MediaWiki ISO format doesn't include microseconds
self.assertNotEqual(t1, t2)
t1 = t1.replace(microsecond=0)
self.assertEqual(t1, t2)
self.assertEqual(ts1, ts2)
示例10: test_add_timedate
# 需要导入模块: from pywikibot import Timestamp [as 别名]
# 或者: from pywikibot.Timestamp import utcnow [as 别名]
def test_add_timedate(self):
"""Test unsupported additions raise NotImplemented."""
t1 = datetime.datetime.utcnow()
t2 = t1 + datetime.timedelta(days=1)
t3 = t1.__add__(t2)
self.assertIs(t3, NotImplemented)
# Now check that the pywikibot sub-class behaves the same way
t1 = Timestamp.utcnow()
t2 = t1 + datetime.timedelta(days=1)
t3 = t1.__add__(t2)
self.assertIs(t3, NotImplemented)
示例11: test_iso_format_with_sep
# 需要导入模块: from pywikibot import Timestamp [as 别名]
# 或者: from pywikibot.Timestamp import utcnow [as 别名]
def test_iso_format_with_sep(self):
"""Test conversion from and to ISO format with separator."""
SEP = '*'
t1 = Timestamp.utcnow().replace(microsecond=0)
ts1 = t1.isoformat(sep=SEP)
t2 = Timestamp.fromISOformat(ts1, sep=SEP)
ts2 = t2.isoformat(sep=SEP)
self.assertEqual(t1, t2)
self.assertEqual(t1, t2)
self.assertEqual(ts1, ts2)
date, sep, time = ts1.partition(SEP)
time = time.rstrip('Z')
self.assertEqual(date, str(t1.date()))
self.assertEqual(time, str(t1.time()))
示例12: test_iso_format
# 需要导入模块: from pywikibot import Timestamp [as 别名]
# 或者: from pywikibot.Timestamp import utcnow [as 别名]
def test_iso_format(self):
"""Test conversion from and to ISO format."""
SEP = 'T'
t1 = Timestamp.utcnow()
ts1 = t1.isoformat()
t2 = Timestamp.fromISOformat(ts1)
ts2 = t2.isoformat()
# MediaWiki ISO format doesn't include microseconds
self.assertNotEqual(t1, t2)
t1 = t1.replace(microsecond=0)
self.assertEqual(t1, t2)
self.assertEqual(ts1, ts2)
date, sep, time = ts1.partition(SEP)
time = time.rstrip('Z')
self.assertEqual(date, str(t1.date()))
self.assertEqual(time, str(t1.time()))
示例13: test_clone
# 需要导入模块: from pywikibot import Timestamp [as 别名]
# 或者: from pywikibot.Timestamp import utcnow [as 别名]
def test_clone(self):
"""Test cloning a Timestamp instance."""
t1 = Timestamp.utcnow()
t2 = t1.clone()
self.assertEqual(t1, t2)
self.assertIsInstance(t2, Timestamp)
示例14: test_sub_timedate
# 需要导入模块: from pywikibot import Timestamp [as 别名]
# 或者: from pywikibot.Timestamp import utcnow [as 别名]
def test_sub_timedate(self):
t1 = T.utcnow()
t2 = t1 - datetime.timedelta(days=1)
td = t1 - t2
self.assertIsInstance(td, datetime.timedelta)
self.assertEqual(t2 + td, t1)
示例15: test_sub_timedelta
# 需要导入模块: from pywikibot import Timestamp [as 别名]
# 或者: from pywikibot.Timestamp import utcnow [as 别名]
def test_sub_timedelta(self):
t1 = T.utcnow()
t2 = t1 - datetime.timedelta(days=1)
self.assertEqual(t1.day - 1, t2.day)
self.assertIsInstance(t2, T)