Example #1
0
 def test_hour_snap_with_offset(self):
   dt = datetime.datetime(2015, 1, 12, 5, 2, 3)
   # snap to beginning of even hours + 3 seconds
   snapped = scheduling_parser.snapped_datetime(dt, 2*60, 3)
   self.assertEqual(snapped,
                    datetime.datetime(2015, 1, 12, 4, 0, 3, tzinfo=pytz.UTC))
   self.assertLess(snapped, dt.replace(tzinfo=pytz.UTC))
Example #2
0
 def test_minute_snap(self):
   dt = datetime.datetime(2015, 1, 12, 5, 2, 3)
   # snap to even minutes
   snapped = scheduling_parser.snapped_datetime(dt, 2, 0)
   self.assertLess(snapped, dt.replace(tzinfo=pytz.UTC))
   self.assertEqual(snapped,
                    datetime.datetime(2015, 1, 12, 5, 2, 0, tzinfo=pytz.UTC))
Example #3
0
 def test_hour_snap(self):
   dt = datetime.datetime(2015, 1, 12, 5, 2, 3)
   # snap to beginning of hour
   snapped = scheduling_parser.snapped_datetime(dt, 60, 0)
   self.assertLess(snapped, dt.replace(tzinfo=pytz.UTC))
   self.assertEqual(snapped,
                    datetime.datetime(2015, 1, 12, 5, 0, 0, tzinfo=pytz.UTC))
Example #4
0
 def test_day_of_week_snap_tue(self):
   dt = datetime.datetime(2015, 12, 23, 5, 2, 3)  # 2015-12-23: Wed
   # snap to Tue 00:00:00
   snapped = scheduling_parser.snapped_datetime(dt, 7*24*60, 24*60*60)
   self.assertEqual(snapped,
                    datetime.datetime(2015, 12, 22, 0, 0, 0, tzinfo=pytz.UTC))
   self.assertLess(snapped, dt.replace(tzinfo=pytz.UTC))
Example #5
0
 def test_offset_larger_than_period(self):
   dt = datetime.datetime(2015, 1, 12, 5, 2, 0)
   # offset is -1:10 with period 1m
   snapped = scheduling_parser.snapped_datetime(dt, 1, -70)
   self.assertLess(snapped, dt.replace(tzinfo=pytz.UTC))
   self.assertEqual(snapped,
                    datetime.datetime(2015, 1, 12, 5, 1, 50, tzinfo=pytz.UTC))
 def test_hour_snap_with_offset(self):
     dt = datetime.datetime(2015, 1, 12, 5, 2, 3)
     # snap to beginning of even hours + 3 seconds
     snapped = scheduling_parser.snapped_datetime(dt, 2 * 60, 3)
     self.assertEqual(
         snapped, datetime.datetime(2015, 1, 12, 4, 0, 3, tzinfo=pytz.UTC))
     self.assertLess(snapped, dt.replace(tzinfo=pytz.UTC))
 def test_hour_snap(self):
     dt = datetime.datetime(2015, 1, 12, 5, 2, 3)
     # snap to beginning of hour
     snapped = scheduling_parser.snapped_datetime(dt, 60, 0)
     self.assertLess(snapped, dt.replace(tzinfo=pytz.UTC))
     self.assertEqual(
         snapped, datetime.datetime(2015, 1, 12, 5, 0, 0, tzinfo=pytz.UTC))
 def test_minute_snap(self):
     dt = datetime.datetime(2015, 1, 12, 5, 2, 3)
     # snap to even minutes
     snapped = scheduling_parser.snapped_datetime(dt, 2, 0)
     self.assertLess(snapped, dt.replace(tzinfo=pytz.UTC))
     self.assertEqual(
         snapped, datetime.datetime(2015, 1, 12, 5, 2, 0, tzinfo=pytz.UTC))
 def test_offset_larger_than_period(self):
     dt = datetime.datetime(2015, 1, 12, 5, 2, 0)
     # offset is -1:10 with period 1m
     snapped = scheduling_parser.snapped_datetime(dt, 1, -70)
     self.assertLess(snapped, dt.replace(tzinfo=pytz.UTC))
     self.assertEqual(
         snapped, datetime.datetime(2015, 1, 12, 5, 1, 50, tzinfo=pytz.UTC))
Example #10
0
 def test_hour_snap_with_negative_offset(self):
   dt = datetime.datetime(2015, 1, 12, 5, 2, 3)
   # snap to 3 seconds before the beginning of even hours
   snapped = scheduling_parser.snapped_datetime(dt, 2*60, -3)
   self.assertLess(snapped, dt.replace(tzinfo=pytz.UTC))
   self.assertEqual(snapped,
                    datetime.datetime(2015, 1, 12, 3, 59, 57, tzinfo=pytz.UTC))
Example #11
0
 def test_minute_snap_already_snapped(self):
   # already matches period and offset
   dt = datetime.datetime(2015, 1, 12, 5, 2, 0)
   # snap to even minutes
   snapped = scheduling_parser.snapped_datetime(dt, 2, 0)
   self.assertEqual(snapped,
                    datetime.datetime(2015, 1, 12, 5, 0, 0, tzinfo=pytz.UTC))
   self.assertLess(snapped, dt.replace(tzinfo=pytz.UTC))
 def test_minute_snap_already_snapped(self):
     # already matches period and offset
     dt = datetime.datetime(2015, 1, 12, 5, 2, 0)
     # snap to even minutes
     snapped = scheduling_parser.snapped_datetime(dt, 2, 0)
     self.assertEqual(
         snapped, datetime.datetime(2015, 1, 12, 5, 0, 0, tzinfo=pytz.UTC))
     self.assertLess(snapped, dt.replace(tzinfo=pytz.UTC))
 def test_day_of_week_snap_tue(self):
     dt = datetime.datetime(2015, 12, 23, 5, 2, 3)  # 2015-12-23: Wed
     # snap to Tue 00:00:00
     snapped = scheduling_parser.snapped_datetime(dt, 7 * 24 * 60,
                                                  24 * 60 * 60)
     self.assertEqual(
         snapped, datetime.datetime(2015, 12, 22, 0, 0, 0, tzinfo=pytz.UTC))
     self.assertLess(snapped, dt.replace(tzinfo=pytz.UTC))
 def test_day_of_week_snap_mon(self):
     # EPOCH starts with a Monday so offset == 0 means Monday
     # offset == 24*60*60 means Tuesday, etc.
     dt = datetime.datetime(2015, 12, 23, 5, 2, 3)  # 2015-12-23: Wed
     snapped = scheduling_parser.snapped_datetime(dt, 7 * 24 * 60, 0)
     self.assertLess(snapped, dt.replace(tzinfo=pytz.UTC))
     self.assertEqual(
         snapped, datetime.datetime(2015, 12, 21, 0, 0, 0, tzinfo=pytz.UTC))
 def test_hour_snap_with_negative_offset(self):
     dt = datetime.datetime(2015, 1, 12, 5, 2, 3)
     # snap to 3 seconds before the beginning of even hours
     snapped = scheduling_parser.snapped_datetime(dt, 2 * 60, -3)
     self.assertLess(snapped, dt.replace(tzinfo=pytz.UTC))
     self.assertEqual(
         snapped, datetime.datetime(2015, 1, 12, 3, 59, 57,
                                    tzinfo=pytz.UTC))
Example #16
0
 def test_day_of_week_snap_mon(self):
   # EPOCH starts with a Monday so offset == 0 means Monday
   # offset == 24*60*60 means Tuesday, etc.
   dt = datetime.datetime(2015, 12, 23, 5, 2, 3)  # 2015-12-23: Wed
   snapped = scheduling_parser.snapped_datetime(dt, 7*24*60, 0)
   self.assertLess(snapped, dt.replace(tzinfo=pytz.UTC))
   self.assertEqual(snapped,
                    datetime.datetime(2015, 12, 21, 0, 0, 0, tzinfo=pytz.UTC))
 def test_day_of_week_snap_wed_0304(self):
     dt = datetime.datetime(2015, 12, 23, 5, 2, 3)  # 2015-12-23: Wed
     # snap to Wed 02:03:04
     snapped = scheduling_parser.snapped_datetime(
         dt, 7 * 24 * 60, 2 * 24 * 60 * 60 + 2 * 60 * 60 + 3 * 60 + 4)
     self.assertLess(snapped, dt.replace(tzinfo=pytz.UTC))
     self.assertEqual(
         snapped,
         datetime.datetime(2015, 12, 23, 02, 03, 04, tzinfo=pytz.UTC))
Example #18
0
 def test_day_of_week_snap_wed_0304(self):
   dt = datetime.datetime(2015, 12, 23, 5, 2, 3)  # 2015-12-23: Wed
   # snap to Wed 02:03:04
   snapped = scheduling_parser.snapped_datetime(
     dt, 7*24*60, 2*24*60*60 + 2*60*60 + 3*60 + 4)
   self.assertLess(snapped, dt.replace(tzinfo=pytz.UTC))
   self.assertEqual(
     snapped,
     datetime.datetime(2015, 12, 23, 02, 03, 04, tzinfo=pytz.UTC))
Example #19
0
 def test_invalid_timezone(self):
   dt = datetime.datetime(
     2015, 1, 1).replace(tzinfo=pytz.timezone('US/Pacific'))
   with self.assertRaises(ValueError):
     scheduling_parser.snapped_datetime(dt, 1, 0)
 def test_invalid_timezone(self):
     dt = datetime.datetime(2015, 1,
                            1).replace(tzinfo=pytz.timezone('US/Pacific'))
     with self.assertRaises(ValueError):
         scheduling_parser.snapped_datetime(dt, 1, 0)