本文整理匯總了Python中khayyam.JalaliDatetime類的典型用法代碼示例。如果您正苦於以下問題:Python JalaliDatetime類的具體用法?Python JalaliDatetime怎麽用?Python JalaliDatetime使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了JalaliDatetime類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_dst
def test_dst(self):
naive_time = JalaliDatetime(1390, 12, 29, 1, 1, 1, 1)
nodst_time = JalaliDatetime(1390, 12, 29, 1, 1, 1, 1, tzinfo=self.tz)
dst_time = nodst_time + timedelta(5)
self.assert_(dst_time.dst() != None, "invalid dst")
self.assert_(nodst_time.dst() == timedelta(0), "invalid dst")
self.assert_(naive_time.dst() == None, "invalid dst")
示例2: test_strftime
def test_strftime(self):
jdate = JalaliDatetime(self.leap_year, 12, 23, 12, 3, 45, 34567)
self.assertEqual(jdate.isoformat(), '%s-12-23T12:3:45.34567' % self.leap_year)
## "%U%W" not implemented
self.assertEqual(jdate.strftime(u'%a%A%b%B%c%C%d%f%H%I%j%m%M%p%S%w%x%X%y%Y%z%Z%%'), 'پپنجشنبهاساسفندپ 23 اس 75 12:3پنجشنبه 23 اسفند 1375 12:3:45 ب.ظ23345671212359123ب.ظ453پنجشنبه 23 اسفند 1375 12:3:45 ب.ظ12:3:45 ب.ظ751375%')
示例3: test_dst
def test_dst(self):
naive_time = JalaliDatetime(1390, 12, 29, 1, 1, 1, 1)
dst_aware_time = JalaliDatetime(1390, 12, 29, 1, 1, 1, 1, tzinfo=self.tz)
dst_time = dst_aware_time + timedelta(5)
self.assertIsNotNone(dst_time.dst(), "invalid dst")
self.assertEqual(dst_aware_time.dst(), timedelta(0), "invalid dst")
self.assertIsNone(naive_time.dst(), "invalid dst")
示例4: test_sub
def test_sub(self):
jalali_time1 = JalaliDatetime(self.leap_year, 12, 23)
jalali_time2 = jalali_time1 - timedelta(10)
self.assertEqual(jalali_time2, JalaliDatetime(self.leap_year, 12, 13))
difference = jalali_time1 - JalaliDatetime(self.leap_year - 1, 12, 1)
self.assertEqual(difference, timedelta(387))
jalali_time1 = JalaliDatetime(self.leap_year, 12, 23, 4, 2, 10, 7)
self.assertEqual(jalali_time1 - jalali_time1.date(), timedelta(hours=4, minutes=2, seconds=10, microseconds=7))
示例5: test_to_from_datetime
def test_to_from_datetime(self):
# Naive
jdate1 = JalaliDatetime.from_datetime(self.naive_jdt.to_datetime())
self.assertEqual(self.naive_jdt, jdate1)
# Aware
jdate2 = JalaliDatetime.from_datetime(self.aware_jdt.to_datetime())
self.assertEqual(self.aware_jdt, jdate2)
示例6: test_instantiate
def test_instantiate(self):
jalali_time = JalaliDatetime(1376, 10, 9, 8, 7, 6, 5)
self.assertFalse(jalali_time is None)
self.assertEqual(JalaliDatetime(jalali_time.todatetime()), jalali_time)
self.assertEqual(JalaliDatetime(jalali_time), jalali_time)
self.assertEqual(JalaliDatetime(jalali_time.date()).date(), jalali_time.date())
self.assertEqual(JalaliDatetime(julian_day=2450674), JalaliDatetime(1376, 5, 23))
示例7: test_strftime_strptime
def test_strftime_strptime(self):
d1 = JalaliDatetime(self.leap_year, 12, 23, 12, 3, 45, 34567)
self.assertEqual(d1.strftime('%Q'), 'Panjshanbeh 23 Esfand 1375 12:03:45 PM')
self.assertEqual(
d1.strptime('Panjshanbeh 23 Esfand 1375 12:03:45 PM', '%Q'),
d1 - timedelta(microseconds=34567))
self.assertEqual(d1.isoformat(), '%s-12-23T12:03:45.034567' % self.leap_year)
tz_datetime = d1.astimezone(teh_tz)
self.assertEqual(tz_datetime.strftime('%Z'), 'Iran/Tehran')
示例8: test_ordinal
def test_ordinal(self):
self.assertEqual(JalaliDatetime.min.toordinal(), 1)
self.assertEqual(JalaliDatetime.max.toordinal(), 1160739)
min_ = JalaliDatetime.fromordinal(JalaliDatetime.min.toordinal())
max_ = JalaliDatetime.fromordinal(JalaliDatetime.max.toordinal())
self.assertEqual(min_.year, 1)
self.assertEqual(min_.month, 1)
self.assertEqual(min_.day, 1)
self.assertEqual(min_, JalaliDatetime.min)
self.assertEqual(max_, JalaliDatetime.max.replace(hour=0, minute=0, second=0, microsecond=0))
示例9: test_fromtimestamp
def test_fromtimestamp(self):
ts = 1471628912.749938
self.assertEqual(
JalaliDatetime.fromtimestamp(ts),
JalaliDatetime.combine(JalaliDatetime(1395, 5, 29), datetime.fromtimestamp(ts).time())
)
self.assertEqual(
JalaliDatetime.utcfromtimestamp(ts),
JalaliDatetime.combine(JalaliDatetime(1395, 5, 29), datetime.utcfromtimestamp(ts).time())
)
示例10: test_algorithm
def test_algorithm(self):
min_date = datetime(1900, 1, 1, 1, 1, 1)
max_days = 5000 # 3000 years !
days = 0
while True:
dt = min_date + timedelta(days=days)
jd = JalaliDatetime(dt)
# print('Processing day: %s' % jd.year)
dt2 = jd.todatetime()
self.assertEqual(dt, dt2)
days += 1
if days > max_days:
break
示例11: test_operators
def test_operators(self):
invalid_object = dict(a=2)
d1 = JalaliDatetime(1361, 6, 15, 10, 1)
d2 = JalaliDatetime(1361, 6, 15, 10, 2)
self.assertRaises(TypeError, d1.__add__, invalid_object)
self.assertRaises(TypeError, d1.__sub__, invalid_object)
self.assertRaises(TypeError, d1.__lt__, invalid_object)
self.assertRaises(TypeError, d1.__gt__, invalid_object)
self.assertRaises(TypeError, d1.__eq__, invalid_object)
self.assertFalse(d1 == 0)
self.assertTrue(d1 == d1.todatetime())
self.assertTrue(d1 < d2)
self.assertTrue(d1 <= d1.copy())
self.assertFalse(d1 > d2)
self.assertTrue(d1 >= d1.copy())
示例12: check_format
def check_format(jdate ,fmt):
jdate_str = jdate.strftime(fmt)
parsed_dt = JalaliDatetime.strptime(jdate_str, fmt)
if jdate != parsed_dt:
print(repr(jdate))
print(jdate_str)
print(repr(parsed_dt))
self.assertEqual(jdate, parsed_dt)
示例13: test_properties
def test_properties(self):
d1 = JalaliDatetime(self.leap_year, 12, 23, 12, 3, 45, 34567)
self.assertEqual(d1.year, self.leap_year)
self.assertEqual(d1.month, 12)
self.assertEqual(d1.day, 23)
self.assertEqual(d1.hour, 12)
self.assertEqual(d1.minute, 3)
self.assertEqual(d1.second, 45)
self.assertEqual(d1.microsecond, 34567)
self.assertEqual(d1.ampm(), u'ب.ظ')
d1.year = 1361
d1.month = 6
d1.day = 15
self.assertRaises(AttributeError, setattr, d1, 'hour', 16)
self.assertRaises(AttributeError, setattr, d1, 'minute', 16)
self.assertRaises(AttributeError, setattr, d1, 'second', 16)
self.assertRaises(AttributeError, setattr, d1, 'microsecond', 16)
self.assertRaises(AttributeError, setattr, d1, 'tzinfo', teh_tz)
示例14: test_today
def test_today(self):
dt = datetime.now().date()
jdt = JalaliDatetime.today().date()
self.assertEqual(jdt, JalaliDate.from_date(dt))
示例15: test_now
def test_now(self):
self.assertTrue(JalaliDatetime.now() != None)