本文整理汇总了Python中khayyam.JalaliDate.replace方法的典型用法代码示例。如果您正苦于以下问题:Python JalaliDate.replace方法的具体用法?Python JalaliDate.replace怎么用?Python JalaliDate.replace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类khayyam.JalaliDate
的用法示例。
在下文中一共展示了JalaliDate.replace方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_year
# 需要导入模块: from khayyam import JalaliDate [as 别名]
# 或者: from khayyam.JalaliDate import replace [as 别名]
def test_year(self):
"""
Testing:
%y Year without century as a zero padded decimal number [00, 99].
%n Year without century as a decimal number in persian form [۱, ۹۹].
%u Year without century as a zero padded decimal number in persian form [۰۱, ۹۹].
%Y Year with century as a decimal number [1-3178].
%N Year with century as a decimal number in persian form [۱-۳۱۷۸].
%O Year with century as a zero padded decimal number in persian form [۰۰۰۱-۳۱۷۸].
"""
self.assertEqual(JalaliDate(1361, 6, 15).strftime('%y'), u'61')
self.assertEqual(JalaliDate(1361, 6, 15).strftime('%Y'), u'1361')
self.assertEqual(JalaliDate(61, 11, 5).strftime('%N'), u'۶۱')
self.assertEqual(JalaliDate(61, 11, 5).strftime('%O'), u'۰۰۶۱')
self.assertEqual(JalaliDate.strptime('94', '%y'), JalaliDate(1394))
self.assertEqual(JalaliDate.strptime('01', '%y'), JalaliDate(1301))
self.assertEqual(JalaliDate.strptime('00', '%y'), JalaliDate(1300))
self.assertEqual(JalaliDate.strptime(u'۹۴', '%n'), JalaliDate(1394))
self.assertEqual(JalaliDate.strptime(u'۱', '%n'), JalaliDate(1301))
self.assertEqual(JalaliDate.strptime(u'۰', '%n'), JalaliDate(1300))
self.assertEqual(JalaliDate.strptime(u'۹۴', '%u'), JalaliDate(1394))
self.assertEqual(JalaliDate.strptime(u'۰۱', '%u'), JalaliDate(1301))
self.assertEqual(JalaliDate.strptime(u'۰۰', '%u'), JalaliDate(1300))
self.assertEqual(JalaliDate.strptime(u'۰۰۴', '%N'), JalaliDate(4, 1, 1))
self.assertEqual(JalaliDate.strptime(u'۰۴', '%N'), JalaliDate(4, 1, 1))
self.assertEqual(JalaliDate.strptime(u'۴', '%N'), JalaliDate(4, 1, 1))
self.assertEqual(JalaliDate.strptime(u'۰۰۴', '%O'), JalaliDate(4, 1, 1))
self.assertEqual(JalaliDate.strptime(u'۰۴', '%O'), JalaliDate(4, 1, 1))
self.assertEqual(JalaliDate.strptime(u'۴', '%O'), JalaliDate(4, 1, 1))
this_century = JalaliDate(int(JalaliDate.today().year/100) * 100)
for i in range(99):
self.assert_parse_and_format(this_century.replace(year=this_century.year+i), '%y')
self.assert_parse_and_format(this_century.replace(year=this_century.year+i), '%n')
self.assert_parse_and_format(this_century.replace(year=this_century.year+i), '%u')
for i in range(1, 1001):
self.assert_parse_and_format(JalaliDate(i), '%Y')
self.assert_parse_and_format(JalaliDate(i), '%N')
self.assert_parse_and_format(JalaliDate(i), '%O')
示例2: test_replace
# 需要导入模块: from khayyam import JalaliDate [as 别名]
# 或者: from khayyam.JalaliDate import replace [as 别名]
def test_replace(self):
d1 = JalaliDate(1391, 12, 30)
self.assertEqual(d1.replace(year=1395), JalaliDate(1395, 12, 30))
self.assertEqual(d1.replace(month=1), JalaliDate(1391, 1, 30))
self.assertEqual(d1.replace(day=1), JalaliDate(1391, 12, 1))
self.assertRaises(ValueError, d1.replace, year=1392)