當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。