Ejemplo n.º 1
0
    def test_get_time_range_with_time_str(self):
        start = RichDateTime(2000, 12, 31, 4, 56, 0, 0, tzinfo=tzlocal())
        self.assertEqual(get_time_range('200012310456', 0), (start, start))

        self.assertEqual(
            get_time_range('200012310456', 5),
            (start, RichDateTime(2000, 12, 31, 5, 1, 0, 0, tzinfo=tzlocal())))

        self.assertEqual(
            get_time_range('200012310456', 60),
            (start, RichDateTime(2000, 12, 31, 5, 56, 0, 0, tzinfo=tzlocal())))

        self.assertEqual(
            get_time_range('200012310456', 1440),
            (start, RichDateTime(2001, 1, 1, 4, 56, 0, 0, tzinfo=tzlocal())))
Ejemplo n.º 2
0
 def test_from_datetime_aware_with_change(self):
     tz = [tzlocal(), self.utc, self.jst, self.pst]
     for tz1, tz2 in ((tz1, tz2) for tz1 in tz for tz2 in tz):
         dt = datetime(2000, 12, 31, 4, 56, 7, 890, tz1)
         rtd = RichDateTime.from_datetime(dt, tz2)
         self.assertEqual(rtd, dt)
         self.assertEqual(rtd.tzinfo, tz2)
Ejemplo n.º 3
0
 def test_from_datetime_naive_to_local(self):
     dt = datetime(2000, 12, 31, 4, 56, 7, 890)
     self.assertEqual(RichDateTime.from_datetime(dt, tzlocal()), datetime(2000, 12, 31, 4, 56, 7, 890, tzlocal()))
Ejemplo n.º 4
0
 def test_mod_by_five_min(self):
     dt = RichDateTime(2000, 12, 31, 4, 56, 7, 890, tzinfo=self.utc)
     self.assertEqual(dt % timedelta(minutes=5), datetime(2000, 12, 31, 4, 55, 0, tzinfo=self.utc))
Ejemplo n.º 5
0
 def test_mod_by_minimum(self):
     dt = RichDateTime(2000, 12, 31, 4, 56, 7, 890, tzinfo=self.utc)
     self.assertEqual(dt % timedelta(seconds=1), datetime(2000, 12, 31, 4, 56, 7, tzinfo=self.utc))
Ejemplo n.º 6
0
 def test_mod_by_illegal_type(self):
     dt = RichDateTime(2000, 12, 31, 4, 56, 7, 890, tzinfo=self.utc)
     self.assertRaises(TypeError, lambda: dt % 0)
Ejemplo n.º 7
0
 def test_set_local_with_localtime(self):
     dt = RichDateTime(2000, 12, 31, 4, 56, 7, 890, tzinfo=tzlocal())
     self.assertEqual(dt.to_local(), datetime(2000, 12, 31, 4, 56, 7, 890, tzlocal()))
Ejemplo n.º 8
0
 def test_epoch_with_specified_timezone(self):
     dt = RichDateTime(2000, 12, 31, 4, 56, 7, 890, tzinfo=self.jst)
     self.assertEqual(dt.epoch(), 978238567)
Ejemplo n.º 9
0
 def test_epoch_with_utc(self):
     dt = RichDateTime(2000, 12, 31, 4, 56, 7, 890, tzinfo=self.utc)
     self.assertEqual(dt.epoch(), 978238567)
Ejemplo n.º 10
0
 def test_strptime_without_tzinfo(self):
     dt = RichDateTime.strptime('20001231045607', '%Y%m%d%H%M%S')
     self.assertEqual(dt, datetime(2000, 12, 31, 4, 56, 7, tzinfo=tzlocal()))
     self.assertEqual(dt.tzinfo, tzlocal())
Ejemplo n.º 11
0
 def test_now_with_tzinfo(self):
     dt = RichDateTime.now(self.utc)
     self.assertEqual(dt.tzinfo, self.utc)
     self.assertTrue(dt <= datetime.now(tzlocal()))
Ejemplo n.º 12
0
 def test_from_datetime_aware_without_change(self):
     for tz in [tzlocal(), self.utc, self.jst, self.pst]:
         dt = datetime(2000, 12, 31, 4, 56, 7, 890, tz)
         rtd = RichDateTime.from_datetime(dt)
         self.assertEqual(rtd, dt)
         self.assertEqual(rtd.tzinfo, tz)
Ejemplo n.º 13
0
 def test_from_datetime_naive_to_specified_timezone(self):
     dt = datetime(2000, 12, 31, 4, 56, 7, 890)
     self.assertEqual(RichDateTime.from_datetime(dt, self.jst), datetime(2000, 12, 31, 4, 56, 7, 890, self.jst))
     self.assertEqual(RichDateTime.from_datetime(dt, self.pst), datetime(2000, 12, 31, 4, 56, 7, 890, self.pst))
Ejemplo n.º 14
0
 def test_from_datetime_naive_to_utc(self):
     dt = datetime(2000, 12, 31, 4, 56, 7, 890)
     self.assertEqual(RichDateTime.from_datetime(dt, self.utc), datetime(2000, 12, 31, 4, 56, 7, 890, self.utc))
Ejemplo n.º 15
0
 def test_new_date_with_time(self):
     dt = RichDateTime(2000, 12, 31, 4, 56, 7, 890, tzinfo=self.utc)
     self.assertEqual(dt, datetime(2000, 12, 31, 4, 56, 7, 890, self.utc))
Ejemplo n.º 16
0
 def test_new_with_specified_timezone(self):
     dt = RichDateTime(2000, 12, 31, 4, 56, 7, 890, tzinfo=self.jst)
     self.assertEqual(dt, datetime(2000, 12, 31, 4, 56, 7, 890, self.jst))
Ejemplo n.º 17
0
 def test_strptime_with_utc(self):
     dt = RichDateTime.strptime('20001231045607', '%Y%m%d%H%M%S', self.utc)
     self.assertEqual(dt, datetime(2000, 12, 31, 4, 56, 7, tzinfo=self.utc))
     self.assertEqual(dt.tzinfo, self.utc)
Ejemplo n.º 18
0
 def test_epoch_with_localtime(self):
     dt = RichDateTime(2000, 12, 31, 4, 56, 7, 890, tzinfo=tzlocal())
     self.assertEqual(dt.epoch(), 978238567)
Ejemplo n.º 19
0
 def test_strptime_with_specified_timezone(self):
     dt = RichDateTime.strptime('20001231045607', '%Y%m%d%H%M%S', self.jst)
     self.assertEqual(dt, datetime(2000, 12, 31, 4, 56, 7, tzinfo=self.jst))
     self.assertEqual(dt.tzinfo, self.jst)
Ejemplo n.º 20
0
 def test_set_local_with_utc(self):
     dt = RichDateTime(2000, 12, 31, 4, 56, 7, 890, tzinfo=self.utc)
     self.assertEqual(dt.to_local(), datetime(2000, 12, 31, 4, 56, 7, 890, tzlocal()) - self.local_to_utc)
Ejemplo n.º 21
0
 def test_new_with_empty_args(self):
     self.assertRaises(TypeError, lambda: RichDateTime())
Ejemplo n.º 22
0
 def test_set_local_with_specified_timezone(self):
     dt = RichDateTime(2000, 12, 31, 4, 56, 7, 890, tzinfo=self.pst)
     offset = self.pst.utcoffset(datetime(2000, 12, 31, 4, 56, 7, 890, tzinfo=self.pst))
     self.assertEqual(dt.to_local(), datetime(2000, 12, 31, 4, 56, 7, 890, tzlocal()) - offset - self.local_to_utc)
Ejemplo n.º 23
0
 def test_new_without_tzinfo(self):
     self.assertRaises(ValueError, lambda: RichDateTime(2000))
Ejemplo n.º 24
0
 def test_mod_by_minus(self):
     dt = RichDateTime(2000, 12, 31, 4, 56, 7, 890, tzinfo=self.utc)
     self.assertRaises(ValueError, lambda: dt % timedelta(seconds=-1))
Ejemplo n.º 25
0
 def test_new_without_day(self):
     self.assertRaises(TypeError, lambda: RichDateTime(2000, 12, tzinfo=self.utc))
Ejemplo n.º 26
0
 def test_mod_by_hour(self):
     dt = RichDateTime(2000, 12, 31, 4, 56, 7, 890, tzinfo=self.utc)
     self.assertEqual(dt % timedelta(hours=1), datetime(2000, 12, 31, 4, 0, 0, tzinfo=self.utc))
Ejemplo n.º 27
0
 def test_new_with_illegal_date(self):
     self.assertRaises(ValueError, lambda: RichDateTime(2000, 12, 32, tzinfo=self.utc))
Ejemplo n.º 28
0
 def test_new_date_only(self):
     dt = RichDateTime(2000, 12, 31, tzinfo=self.utc)
     self.assertEqual(dt, datetime(2000, 12, 31, 0, 0, 0, 0, self.utc))
Ejemplo n.º 29
0
 def test_from_datetime_naive_to_naive(self):
     dt = datetime(2000, 12, 31, 4, 56, 7, 890)
     self.assertRaises(ValueError, lambda: RichDateTime.from_datetime(dt))