コード例 #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())))
コード例 #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)
コード例 #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()))
コード例 #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))
コード例 #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))
コード例 #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)
コード例 #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()))
コード例 #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)
コード例 #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)
コード例 #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())
コード例 #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()))
コード例 #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)
コード例 #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))
コード例 #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))
コード例 #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))
コード例 #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))
コード例 #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)
コード例 #18
0
 def test_epoch_with_localtime(self):
     dt = RichDateTime(2000, 12, 31, 4, 56, 7, 890, tzinfo=tzlocal())
     self.assertEqual(dt.epoch(), 978238567)
コード例 #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)
コード例 #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)
コード例 #21
0
 def test_new_with_empty_args(self):
     self.assertRaises(TypeError, lambda: RichDateTime())
コード例 #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)
コード例 #23
0
 def test_new_without_tzinfo(self):
     self.assertRaises(ValueError, lambda: RichDateTime(2000))
コード例 #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))
コード例 #25
0
 def test_new_without_day(self):
     self.assertRaises(TypeError, lambda: RichDateTime(2000, 12, tzinfo=self.utc))
コード例 #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))
コード例 #27
0
 def test_new_with_illegal_date(self):
     self.assertRaises(ValueError, lambda: RichDateTime(2000, 12, 32, tzinfo=self.utc))
コード例 #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))
コード例 #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))