def test_months_in_wrong_order(self): start = common_timezone.datetime(2014, 11, 1) end = common_timezone.math(start, operator.sub, datetime.timedelta(days=33)) count = len(list(common_timezone.monthly_iter(start, end))) # No error is thrown, and no iteration happens self.assertEqual(count, 0)
def test_not_crossing_dst(self): # Test not crossing daylight savings time delta = datetime.timedelta(days=7) expected = self.dst_time + delta outcome = common_timezone.math(self.dst_time, operator.add, delta) self.assertEqual(expected.replace(tzinfo=None), outcome.replace(tzinfo=None)) self.assertTrue(common_timezone.is_daylight_savings_time(outcome))
def test_crossing_dst_keep_hour(self): # Test crossing daylight savings time delta = datetime.timedelta(days=180) expected = self.dst_time + delta outcome = common_timezone.math(self.dst_time, operator.add, delta, keep_hour=True) self.assertEqual(expected.replace(tzinfo=None), outcome.replace(tzinfo=None)) self.assertFalse(common_timezone.is_daylight_savings_time(outcome))
def test_crossing_dst_with_hour_delta(self): # Test crossing daylight savings time with delta that has an hour in it delta = datetime.timedelta(days=180, hours=2) expected = self.dst_time - delta outcome = common_timezone.math(self.dst_time, operator.sub, delta, keep_hour=True) self.assertEqual(expected.replace(tzinfo=None), outcome.replace(tzinfo=None)) self.assertFalse(common_timezone.is_daylight_savings_time(outcome))
def test_crossing_dst_default(self): # Test crossing daylight savings time, hour changes (default behaviour) delta = datetime.timedelta(days=180) expected = common_timezone.parse( '12/27/2014 23:00' ) # Would be 12/27/2014, but normalize subtracts an hour outcome = common_timezone.math(self.dst_time, operator.add, delta, keep_hour=False) self.assertEqual(expected.replace(tzinfo=None, hour=expected.hour), outcome.replace(tzinfo=None)) self.assertFalse(common_timezone.is_daylight_savings_time(outcome))
def test_multiple_months(self): start = common_timezone.datetime(2014, 11, 1) end = common_timezone.math(start, operator.add, datetime.timedelta(days=33)) count = 0 for date in common_timezone.monthly_iter(start, end): if count == 0: # On the first month self.assertEqual(date.month, start.month) self.assertEqual(date.month, start.month) else: # On the second month self.assertEqual(date.month, end.month) self.assertEqual(date.month, end.month) count += 1 self.assertEqual(count, 2)