本文整理匯總了Python中khayyam.JalaliDatetime.todatetime方法的典型用法代碼示例。如果您正苦於以下問題:Python JalaliDatetime.todatetime方法的具體用法?Python JalaliDatetime.todatetime怎麽用?Python JalaliDatetime.todatetime使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類khayyam.JalaliDatetime
的用法示例。
在下文中一共展示了JalaliDatetime.todatetime方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_instantiate
# 需要導入模塊: from khayyam import JalaliDatetime [as 別名]
# 或者: from khayyam.JalaliDatetime import todatetime [as 別名]
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))
示例2: test_algorithm
# 需要導入模塊: from khayyam import JalaliDatetime [as 別名]
# 或者: from khayyam.JalaliDatetime import todatetime [as 別名]
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
示例3: test_operators
# 需要導入模塊: from khayyam import JalaliDatetime [as 別名]
# 或者: from khayyam.JalaliDatetime import todatetime [as 別名]
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())
示例4: TestJalaliDateTime
# 需要導入模塊: from khayyam import JalaliDatetime [as 別名]
# 或者: from khayyam.JalaliDatetime import todatetime [as 別名]
class TestJalaliDateTime(unittest.TestCase):
def setUp(self):
self.leap_year = 1375
self.naive_jdt = JalaliDatetime(self.leap_year, 12, 30, 10, 2, 1, 3)
self.aware_jdt = JalaliDatetime(self.leap_year, 12, 30, 10, 2, 1, 3, TehranTimezone())
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))
def test_to_from_datetime(self):
# Naive
jalali_time1 = JalaliDatetime(self.naive_jdt.todatetime())
self.assertEqual(self.naive_jdt, jalali_time1)
# Aware
jalali_time2 = JalaliDatetime(self.aware_jdt.todatetime())
self.assertEqual(self.aware_jdt, jalali_time2)
def test_today(self):
dt = datetime.now().date()
jdt = JalaliDatetime.today().date()
self.assertEqual(jdt, JalaliDate(dt))
def test_now(self):
self.assertIsNotNone(JalaliDatetime.now())
self.assertIsNone(JalaliDatetime.now().tzinfo)
self.assertIsNotNone(JalaliDatetime.now(TehranTimezone()).tzinfo)
def test_utcnow(self):
jalali_utcnow = JalaliDatetime.utcnow()
datetime_utcnow = jalali_utcnow.todatetime()
self.assertEqual(jalali_utcnow.time(), datetime_utcnow.time())
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')
def test_iso_format(self):
jalali_time = JalaliDatetime(self.leap_year, 12, 23)
self.assertEqual(jalali_time.isoformat(), '%s-12-23T00:00:00.000000' % self.leap_year)
jalali_time = JalaliDatetime(self.leap_year, 12, 23, tzinfo=teh_tz)
self.assertEqual(jalali_time.isoformat(), '%s-12-23T00:00:00.000000+03:30' % self.leap_year)
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
def test_add(self):
jalali_time1 = JalaliDatetime(self.leap_year, 12, 23)
jalali_tme2 = jalali_time1 + timedelta(10)
self.assertEqual(jalali_tme2, JalaliDatetime(self.leap_year + 1, 1, 3))
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))
def test_lt_gt_le_ge_ne_eg(self):
jalali_time1 = JalaliDatetime(self.leap_year, 12, 23)
jalali_time2 = JalaliDatetime(self.leap_year, 12, 24)
jalali_time3 = JalaliDatetime(self.leap_year, 12, 24)
self.assertTrue(jalali_time1 <= jalali_time2)
self.assertTrue(jalali_time1 != jalali_time2)
self.assertFalse(jalali_time1 > jalali_time2)
self.assertTrue(jalali_time2 == jalali_time3)
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))
#.........這裏部分代碼省略.........
示例5: TestJalaliDateTime
# 需要導入模塊: from khayyam import JalaliDatetime [as 別名]
# 或者: from khayyam.JalaliDatetime import todatetime [as 別名]
class TestJalaliDateTime(unittest.TestCase):
def setUp(self):
self.leap_year = 1375
self.naive_jdt = JalaliDatetime(self.leap_year, 12, 30, 10, 2, 1, 3)
self.aware_jdt = JalaliDatetime(self.leap_year, 12, 30, 10, 2, 1, 3, TehranTimezone())
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))
self.assertEqual(
JalaliDatetime(1361, 6, 15, tzinfo=TehranTimezone),
JalaliDatetime(1361, 6, 15, tzinfo=TehranTimezone())
)
def test_to_from_datetime(self):
# Naive
jalali_time1 = JalaliDatetime(self.naive_jdt.todatetime())
self.assertEqual(self.naive_jdt, jalali_time1)
# Aware
jalali_time2 = JalaliDatetime(self.aware_jdt.todatetime())
self.assertEqual(self.aware_jdt, jalali_time2)
def test_today(self):
dt = datetime.now().date()
jdt = JalaliDatetime.today().date()
self.assertEqual(jdt, JalaliDate(dt))
def test_now(self):
self.assertIsNotNone(JalaliDatetime.now())
self.assertIsNone(JalaliDatetime.now().tzinfo)
self.assertIsNotNone(JalaliDatetime.now(TehranTimezone()).tzinfo)
def test_utcnow(self):
jalali_utcnow = JalaliDatetime.utcnow()
datetime_utcnow = jalali_utcnow.todatetime()
self.assertEqual(jalali_utcnow.time(), datetime_utcnow.time())
self.assertEqual(jalali_utcnow.timetz(), datetime_utcnow.timetz())
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')
def test_iso_format(self):
jalali_time = JalaliDatetime(self.leap_year, 12, 23)
self.assertEqual(jalali_time.isoformat(), '%s-12-23T00:00:00.000000' % self.leap_year)
jalali_time = JalaliDatetime(self.leap_year, 12, 23, tzinfo=teh_tz)
self.assertEqual(jalali_time.isoformat(), '%s-12-23T00:00:00.000000+03:30' % self.leap_year)
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
def test_add(self):
jalali_time1 = JalaliDatetime(self.leap_year, 12, 23)
jalali_tme2 = jalali_time1 + timedelta(10)
self.assertEqual(jalali_tme2, JalaliDatetime(self.leap_year + 1, 1, 3))
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))
def test_lt_gt_le_ge_ne_eg(self):
jalali_time1 = JalaliDatetime(self.leap_year, 12, 23)
jalali_time2 = JalaliDatetime(self.leap_year, 12, 24)
jalali_time3 = JalaliDatetime(self.leap_year, 12, 24)
self.assertTrue(jalali_time1 <= jalali_time2)
self.assertTrue(jalali_time1 != jalali_time2)
self.assertFalse(jalali_time1 > jalali_time2)
self.assertTrue(jalali_time2 == jalali_time3)
#.........這裏部分代碼省略.........