示例#1
0
    def test_already_floored_hour_multiple(self):
        for hour in [0, 8, 16]:
            date = datetime(2017, 11, 17, hour, 0)
            round_to = 60 * 60 * 8
            rounded = floor_datetime(date, round_to)
            expected = date
            self.assertEqual(rounded, expected)

        for hour in [0, 5, 10, 15, 20]:
            date = datetime(2017, 11, 17, hour, 0)
            round_to = 60 * 60 * 5
            rounded = floor_datetime(date, round_to)
            expected = date
            self.assertEqual(rounded, expected)
        pass
示例#2
0
 def test_already_floored_day(self):
     for day in range(1, 28):
         date = datetime(2017, 4, day, 0, 0, 0)
         round_to = 60 * 60 * 24
         rounded = floor_datetime(date, round_to)
         expected = date
         self.assertEqual(rounded, expected)
     pass
示例#3
0
 def test_next_hour(self):
     for hour in range(0, 1):
         date = datetime(2017, 11, 17, hour, 55, 0)
         round_to = 60 * 60
         rounded = floor_datetime(date, round_to)
         expected = date - timedelta(minutes=55)
         self.assertEqual(rounded, expected)
     pass
示例#4
0
 def test_already_floored_second(self):
     for second in range(0, 60):
         date = datetime(2017, 11, 17, 10, 23, second)
         round_to = 1
         rounded = floor_datetime(date, round_to)
         expected = date
         self.assertEqual(rounded, expected)
     pass
示例#5
0
 def test_already_floored_minute(self):
     for minute in range(0, 60):
         date = datetime(2017, 11, 17, 10, minute, 0)
         round_to = 60
         rounded = floor_datetime(date, round_to)
         expected = date
         self.assertEqual(rounded, expected)
     pass
示例#6
0
 def test_already_floored_hour(self):
     for hour in range(0, 24):
         date = datetime(2017, 11, 17, hour, 0, 0)
         round_to = 60 * 60
         rounded = floor_datetime(date, round_to)
         expected = date
         self.assertEqual(rounded, expected)
     pass
示例#7
0
 def test_all_hours_in_day(self):
     for day in range(1, 28):
         for hour in range(1, 24):
             date = datetime(2017, 11, day, hour, 0, 0)
             round_to = 60 * 60 * 24
             rounded = floor_datetime(date, round_to)
             expected = date - timedelta(hours=hour)  # always current day
             self.assertEqual(rounded, expected)
     pass
示例#8
0
 def test_all_minutes_in_hour(self):
     for hour in range(0, 24):
         for minute in range(1, 60):
             date = datetime(2017, 11, 17, hour, minute, 0)
             round_to = 60 * 60
             rounded = floor_datetime(date, round_to)
             expected = date - timedelta(
                 minutes=minute)  # always current hour
             self.assertEqual(rounded, expected)
     pass