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


Python JalaliDate.replace方法代码示例

本文整理汇总了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')
开发者ID:Mazafard,项目名称:khayyam,代码行数:47,代码来源:test_jalali_date_formatter.py

示例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)
开发者ID:siminbar,项目名称:khayyam,代码行数:8,代码来源:test_jalali_date.py


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