當前位置: 首頁>>代碼示例>>Python>>正文


Python JalaliDatetime.replace方法代碼示例

本文整理匯總了Python中khayyam.JalaliDatetime.replace方法的典型用法代碼示例。如果您正苦於以下問題:Python JalaliDatetime.replace方法的具體用法?Python JalaliDatetime.replace怎麽用?Python JalaliDatetime.replace使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在khayyam.JalaliDatetime的用法示例。


在下文中一共展示了JalaliDatetime.replace方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_timezone

# 需要導入模塊: from khayyam import JalaliDatetime [as 別名]
# 或者: from khayyam.JalaliDatetime import replace [as 別名]
    def test_timezone(self):
        """
        Testing:
            %z            UTC offset in the form +HHMM or -HHMM (empty string if the the object is naive).
            %o            UTC offset in the form +HHMM or -HHMM (empty string if the the object is naive) in persian format i.e +۰۳:۳۰.
            %Z            Time zone name (empty string if the object is naive).
        """
        # Test Timezone
        tz_dt = JalaliDatetime(tzinfo=Timezone(timedelta(minutes=10)))
        naive_dt = tz_dt.replace(tzinfo=None)
        self.assertEqual(JalaliDatetime.strptime('00:10', '%z'), tz_dt)
        self.assertEqual(JalaliDatetime.strptime('', '%z'), naive_dt)
        self.assertEqual(tz_dt.strftime('%z'), '+00:10')
        tz_dt = JalaliDatetime(tzinfo=Timezone(timedelta(minutes=-30)))
        self.assertEqual(tz_dt.strftime('%z'), '-00:30')
        self.assertEqual(tz_dt.strftime('%o'), u'-۰۰:۳۰')
        self.assertEqual(JalaliDatetime.strptime('', '%o'), JalaliDatetime())
        self.assertEqual(JalaliDatetime.strptime('00:00', '%z'), JalaliDatetime())
        self.assertEqual(JalaliDatetime.strptime('00:01', '%z'), JalaliDatetime(tzinfo=Timezone(timedelta(minutes=1))))
        self.assertNotEqual(JalaliDatetime.strptime('04:30', '%z'), JalaliDatetime.strptime('04:31', '%z'))
        self.assertEqual(JalaliDatetime.strptime('04:30', '%z'), JalaliDatetime.strptime('04:30', '%z'))
        self.assertNotEqual(JalaliDatetime.strptime('04:30', '%z'), JalaliDatetime(tzinfo=teh_tz))
        self.assertEqual(JalaliDatetime.strptime('+04:30', '%z').utcoffset(), timedelta(hours=4.50))
        self.assertEqual(tz_dt.strftime('%z'), tz_dt.strftime('%Z'))
        self.assertEqual(naive_dt.strftime('%z'), '')
        self.assertEqual(naive_dt.strftime('%Z'), '')

        self.assertEqual(JalaliDatetime.strptime(u'۰۰:۰۰', '%o'), JalaliDatetime())
        self.assertEqual(JalaliDatetime.strptime(u'۰۰:۰۱', '%o'), JalaliDatetime(tzinfo=Timezone(timedelta(minutes=1))))
        self.assertNotEqual(JalaliDatetime.strptime(u'۰۴:۳۰', '%o'), JalaliDatetime.strptime('04:31', '%z'))
        self.assertEqual(JalaliDatetime.strptime(u'۰۴:۳۰', '%o'), JalaliDatetime.strptime('04:30', '%z'))
        self.assertNotEqual(JalaliDatetime.strptime(u'۰۴:۳۰', '%o'), JalaliDatetime(tzinfo=teh_tz))
        self.assertEqual(JalaliDatetime.strptime(u'+۰۴:۳۰', '%o').utcoffset(), timedelta(hours=4.50))
        self.assertEqual(naive_dt.strftime('%o'), '')

        self.assertEqual(
            JalaliDatetime(1394, 4, 28, 18, 14, 35, 962659, Timezone(timedelta(.3))).strftime('%Y-%m-%d %H:%M:%S.%f %z'),
            '1394-04-28 18:14:35.962659 +07:12')

        self.assertEqual(
            JalaliDatetime.strptime('1394-04-28 18:14:35.962659 +07:12', '%Y-%m-%d %H:%M:%S.%f %z'),
            JalaliDatetime(1394, 4, 28, 18, 14, 35, 962659, Timezone(timedelta(.3)))
            )

        self.assertEqual(
            JalaliDatetime.strptime(u'1394-تیر-29 دوشنبه 00:05:14.113389 +04:30', '%Y-%B-%d %A %H:%M:%S.%f %z'),
            JalaliDatetime(1394, 4, 29, 0, 5, 14, 113389, Timezone(timedelta(hours=4, minutes=30)))
        )
開發者ID:pylover,項目名稱:khayyam,代碼行數:50,代碼來源:test_jalali_datetime_formatter.py

示例2: test_replace

# 需要導入模塊: from khayyam import JalaliDatetime [as 別名]
# 或者: from khayyam.JalaliDatetime import replace [as 別名]
 def test_replace(self):
     d1 = JalaliDatetime(1391, 12, 30)
     self.assertEqual(d1.replace(year=1395), JalaliDatetime(1395, 12, 30))
     self.assertEqual(d1.replace(month=1),   JalaliDatetime(1391, 1, 30))
     self.assertEqual(d1.replace(day=1),     JalaliDatetime(1391, 12, 1))
     self.assertRaises(ValueError, d1.replace, year=1392)
開發者ID:Mazafard,項目名稱:khayyam,代碼行數:8,代碼來源:test_jalali_datetime.py


注:本文中的khayyam.JalaliDatetime.replace方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。