Esempio n. 1
0
class TestTehTz(unittest.TestCase):
    
    def setUp(self):
        self.teh_tz = TehranTimezone()
        self.dt = datetime(2000, 1, 1)
        self.dtz = datetime(2000, 1, 1, tzinfo=self.teh_tz)
        self.another_tz = Timezone(timedelta(hours=5))
        self.zero_tz = Timezone(timedelta())

    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.teh_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")

    def test_repr(self):
        t = TehranTimezone()
        self.assertEqual(type(repr(t)), str)
        self.assertEqual(repr(t), '+03:30 dst:60')

    def test_fromutc(self):
        self.assertRaises(ValueError, self.teh_tz.fromutc, JalaliDatetime(1390, 12, 29, 1, 1, 1, 1, tzinfo=self.another_tz))
        self.assertRaises(ValueError, self.teh_tz.fromutc, JalaliDatetime(1390, 12, 29, 1, 1, 1, 1))
        self.assertEqual(
            self.teh_tz.fromutc(JalaliDatetime(1390, 2, 1, 1, 1, 1, 1, tzinfo=self.teh_tz)),
            JalaliDatetime(1390, 2, 1, 5, 31, 1, 1, tzinfo=self.teh_tz)
        )
Esempio n. 2
0
    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())
        )
Esempio n. 3
0
class TestTehTz(unittest.TestCase):
    def setUp(self):
        self.teh_tz = TehranTimezone()
        self.dt = datetime(2000, 1, 1)
        self.dtz = datetime(2000, 1, 1, tzinfo=self.teh_tz)
        self.another_tz = Timezone(timedelta(hours=5))
        self.zero_tz = Timezone(timedelta())

    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.teh_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")

    def test_repr(self):
        t = TehranTimezone()
        self.assertEqual(type(repr(t)), str)
        self.assertEqual(repr(t), '+03:30 dst:60')

    def test_fromutc(self):
        self.assertRaises(
            ValueError, self.teh_tz.fromutc,
            JalaliDatetime(1390, 12, 29, 1, 1, 1, 1, tzinfo=self.another_tz))
        self.assertRaises(ValueError, self.teh_tz.fromutc,
                          JalaliDatetime(1390, 12, 29, 1, 1, 1, 1))
        self.assertEqual(
            self.teh_tz.fromutc(
                JalaliDatetime(1390, 2, 1, 1, 1, 1, 1, tzinfo=self.teh_tz)),
            JalaliDatetime(1390, 2, 1, 5, 31, 1, 1, tzinfo=self.teh_tz))
Esempio n. 4
0
 def test_repr(self):
     t = TehranTimezone()
     self.assertEqual(type(repr(t)), str)
     self.assertEqual(repr(t), '+03:30 dst:60')
Esempio n. 5
0
 def setUp(self):
     self.tz = TehranTimezone()
     self.dt = datetime(2000, 1, 1)
     self.dtz = datetime(2000, 1, 1, tzinfo=self.tz)
Esempio n. 6
0
 def test_now(self):
     self.assertIsNotNone(JalaliDatetime.now())
     self.assertIsNone(JalaliDatetime.now().tzinfo)
     self.assertIsNotNone(JalaliDatetime.now(TehranTimezone()).tzinfo)
Esempio n. 7
0
 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())
Esempio n. 8
0
 def setUp(self):
     self.teh_tz = TehranTimezone()
     self.dt = datetime(2000, 1, 1)
     self.dtz = datetime(2000, 1, 1, tzinfo=self.teh_tz)
     self.another_tz = Timezone(timedelta(hours=5))
     self.zero_tz = Timezone(timedelta())
Esempio n. 9
0
 def setUp(self):
     self.teh_tz = TehranTimezone()
     self.dt = datetime(2000, 1, 1)
     self.dtz = datetime(2000, 1, 1, tzinfo=self.teh_tz)
     self.another_tz = Timezone(timedelta(hours=5))
     self.zero_tz = Timezone(timedelta())