예제 #1
0
 def test_single_month(self):
     start = common_timezone.now()
     end = start
     count = 0
     for date in common_timezone.monthly_iter(start, end):
         self.assertEqual(date.month, start.month)
         self.assertEqual(date.year, start.year)
         count += 1
     self.assertEqual(count, 1)
예제 #2
0
 def test_passing_in_timezone(self):
     # Test passing in utc
     now = common_timezone.now(tz=pytz.utc)
     date = now.date()
     time = now.time()
     self.assertTrue(time.tzinfo is None)
     datetime_combined = datetime.datetime.combine(date, time)
     timezone_combined = common_timezone.combine(date, time, tz=pytz.utc)
     self.assertEqual(datetime_combined,
                      timezone_combined.replace(tzinfo=None))
     self.assertEqual(timezone_combined.tzinfo, now.tzinfo)
예제 #3
0
 def test_to_end_of_day(self):
     time = common_timezone.now()
     start = common_timezone.to_end_of_day(time)
     self.assertEqual(time.year, start.year)
     self.assertEqual(time.month, start.month)
     self.assertEqual(time.day, start.day)
     self.assertEqual(time.tzinfo, start.tzinfo)
     self.assertEqual(start.hour, 23)
     self.assertEqual(start.minute, 59)
     self.assertEqual(start.second, 59)
     self.assertEqual(start.microsecond, 999999)
예제 #4
0
 def test_default_behaviour(self):
     # Test default behaviour
     now = common_timezone.now()
     date = now.date()
     time = now.time()
     self.assertTrue(time.tzinfo is None)
     datetime_combined = datetime.datetime.combine(date, time)
     timezone_combined = common_timezone.combine(date, time)
     self.assertEqual(datetime_combined,
                      timezone_combined.replace(tzinfo=None))
     self.assertEqual(timezone_combined.tzinfo, now.tzinfo)
예제 #5
0
 def test_time_having_tzinfo(self):
     # Test time having tzinfo
     now = common_timezone.now(tz=pytz.utc)
     date = now.date()
     time = now.time()
     self.assertTrue(time.tzinfo is None)
     time = time.replace(tzinfo=pytz.utc)  # Ensure that tzinfo is set
     datetime_combined = datetime.datetime.combine(date,
                                                   time)  # Comes back aware
     timezone_combined = common_timezone.combine(date, time)
     self.assertEqual(datetime_combined, timezone_combined)
     self.assertEqual(timezone_combined.tzinfo, now.tzinfo)
예제 #6
0
 def test_non_dst_time(self):
     non_dst_time = common_timezone.now().replace(month=12)
     self.assertFalse(
         common_timezone.is_daylight_savings_time(non_dst_time))
예제 #7
0
 def test_dst_time(self):
     dst_time = common_timezone.now().replace(month=7)
     self.assertTrue(common_timezone.is_daylight_savings_time(dst_time))
예제 #8
0
 def test_conversion_works_as_expected(self):
     # Test that the conversion works as expected
     now = common_timezone.now(tz=pytz.utc).replace(tzinfo=None,
                                                    microsecond=0)
     date_now = datetime.datetime.utcnow().replace(microsecond=0)
     self.assertEqual(date_now, now)
예제 #9
0
 def test_equality_of_dates_and_times(self):
     # Test equality of the dates and times
     now = common_timezone.now().replace(tzinfo=None, microsecond=0)
     date_now = datetime.datetime.now().replace(microsecond=0)
     self.assertEqual(date_now, now)
예제 #10
0
 def test_passing_in_timezone(self):
     # Test that we can put in a custom timezone if needed
     now = common_timezone.now(tz=pytz.utc)
     self.assertEqual(now.tzinfo, pytz.utc)
예제 #11
0
 def test_getting_back_expected_timezone_by_default(self):
     # Test that we get back the default timezone we expect
     now = common_timezone.now()
     # Depending on the time of year, now.tzinfo changes for day light savings.
     self.assertEqual(now.tzinfo._tzinfos,
                      pytz.timezone(settings.TIME_ZONE)._tzinfos)
예제 #12
0
 def test_string_with_timezone(self):
     # Test returning with timezone information provided by the string
     expected = common_timezone.now()
     outcome = common_timezone.parse(str(expected))
     self.assertEqual(expected, outcome)