def test_method(self): self.assertEqual(pytime.daysrange('2015-5-17', '2015-5-21'), [datetime.date(2015, 5, 21), datetime.date(2015, 5, 20), datetime.date(2015, 5, 19), datetime.date(2015, 5, 18), datetime.date(2015, 5, 17)]) self.assertEqual(pytime.daysrange('2015-5-17', '2015-5-21', True), [datetime.date(2015, 5, 20), datetime.date(2015, 5, 19), datetime.date(2015, 5, 18)]) self.assertEqual(pytime.daysrange(datetime.date(2015, 5, 17), '2015-5-21', True), pytime.daysrange('2015-5-17', datetime.date(2015, 5, 21), True)) this1 = pytime.lastday(2015, 5) == datetime.date(2015, 5, 31) self.assertTrue(this1) this2 = pytime.lastday(current_year) == pytime.lastday() self.assertTrue(this2) this3 = pytime.lastday(month=6) == pytime.lastday(current_year, 6) self.assertTrue(this3) this4 = pytime.midnight('2015-5-17') == datetime.datetime(2015, 5, 17, 0, 0, 0) self.assertTrue(this4) this5 = pytime.midnight() == datetime.datetime.combine(datetime.datetime.today(), datetime.datetime.min.time()) self.assertTrue(this5) this6 = pytime.before('2015-5-17') == datetime.datetime(2015, 5, 17, 0, 0) self.assertTrue(this6) this7 = pytime.before('2015-5-17', '3days 3hou 2mi 1s') == datetime.datetime(2015, 5, 13, 20, 57, 59) self.assertTrue(this7) this8 = pytime.before('2015-5-17 23:23:23', '2ye 3mon 2dy 1s') == datetime.datetime(2013, 2, 14, 23, 59, 59) self.assertTrue(this8) this9 = pytime.after('2015-5-17', '32month 2days 1years') == datetime.datetime(2019, 1, 19, 0, 0) self.assertTrue(this9) this10 = pytime.after('2015-5-17 23:23:23', '59days 280minu, 22222sec') == datetime.datetime(2015, 7, 15, 10, 50, 22) self.assertTrue(this10) this11 = pytime.after('2015-5-17', '59days 9week') == datetime.datetime(2015, 9, 16, 0, 0) self.assertTrue(this11) this12 = pytime.before('2015-5-17', '5y 6m 7w 8d 9h 10mi 59s') == datetime.datetime(2009, 9, 20, 14, 49, 1) self.assertTrue(this12) self.assertEqual(pytime.this_week('2015-5-17'), (datetime.date(2015, 5, 11), datetime.date(2015, 5, 18))) self.assertEqual(pytime.this_week('2015-5-17', True), (datetime.date(2015, 5, 11), datetime.date(2015, 5, 17))) self.assertEqual(pytime.last_week('2015-5-17'), (datetime.date(2015, 5, 4), datetime.date(2015, 5, 12))) self.assertEqual(pytime.last_week('2015-5-17', True), (datetime.date(2015, 5, 4), datetime.date(2015, 5, 11))) self.assertEqual(pytime.next_week('2015-5-17'), (datetime.date(2015, 5, 18), datetime.date(2015, 5, 26))) self.assertEqual(pytime.next_week('2015-5-17', True), (datetime.date(2015, 5, 18), datetime.date(2015, 5, 25))) self.assertEqual(pytime.this_month('2015-5-17'), (datetime.date(2015, 5, 1), datetime.date(2015, 6, 1))) self.assertEqual(pytime.this_month('2015-5-17', True), (datetime.date(2015, 5, 1), datetime.date(2015, 5, 31))) self.assertEqual(pytime.last_month('2015-5-17'), (datetime.date(2015, 4, 1), datetime.date(2015, 5, 1))) self.assertEqual(pytime.last_month('2015-5-17', True), (datetime.date(2015, 4, 1), datetime.date(2015, 4, 30))) self.assertEqual(pytime.next_month('2015-5-17'), (datetime.date(2015, 6, 1), datetime.date(2015, 7, 1))) self.assertEqual(pytime.next_month('2015-5-17', True), (datetime.date(2015, 6, 1), datetime.date(2015, 6, 30))) self.assertTrue(pytime.next_month(1432310400 + gmt8offset, True), (datetime.datetime(2015, 6, 1), datetime.datetime(2015, 6, 30)))
def test_method(self): self.assertEqual(pytime.days_range('2015-5-17', '2015-5-21'), [datetime.date(2015, 5, 21), datetime.date(2015, 5, 20), datetime.date(2015, 5, 19), datetime.date(2015, 5, 18), datetime.date(2015, 5, 17)]) self.assertEqual(pytime.days_range('2015-5-17', '2015-5-21', True), [datetime.date(2015, 5, 20), datetime.date(2015, 5, 19), datetime.date(2015, 5, 18)]) self.assertEqual(pytime.days_range(datetime.date(2015, 5, 17), '2015-5-21', True), pytime.days_range('2015-5-17', datetime.date(2015, 5, 21), True)) this1 = pytime.last_day(2015, 5) == datetime.date(2015, 5, 31) self.assertTrue(this1) this2 = pytime.last_day(current_year) == pytime.last_day() self.assertTrue(this2) this3 = pytime.last_day(month=6) == pytime.last_day(current_year, 6) self.assertTrue(this3) this4 = pytime.midnight('2015-5-17') == datetime.datetime(2015, 5, 17, 0, 0, 0) self.assertTrue(this4) this5 = pytime.midnight() == datetime.datetime.combine(datetime.datetime.today(), datetime.datetime.min.time()) self.assertTrue(this5) this6 = pytime.before('2015-5-17') == datetime.datetime(2015, 5, 17, 0, 0) self.assertTrue(this6) this7 = pytime.before('2015-5-17', '3days 3hou 2mi 1s') == datetime.datetime(2015, 5, 13, 20, 57, 59) self.assertTrue(this7) this8 = pytime.before('2015-5-17 23:23:23', '2ye 3mon 2dy 1s') == datetime.datetime(2013, 2, 14, 23, 59, 59) self.assertTrue(this8) this9 = pytime.after('2015-5-17', '32month 2days 1years') == datetime.datetime(2019, 1, 19, 0, 0) self.assertTrue(this9) this10 = pytime.after('2015-5-17 23:23:23', '59days 280minu, 22222sec') == datetime.datetime(2015, 7, 15, 10, 50, 22) self.assertTrue(this10) this11 = pytime.after('2015-5-17', '59days 9week') == datetime.datetime(2015, 9, 16, 0, 0) self.assertTrue(this11) this12 = pytime.before('2015-5-17', '5y 6m 7w 8d 9h 10mi 59s') == datetime.datetime(2009, 9, 20, 14, 49, 1) self.assertTrue(this12) self.assertEqual(pytime.this_week('2015-5-17'), (datetime.date(2015, 5, 11), datetime.date(2015, 5, 18))) self.assertEqual(pytime.this_week('2015-5-17', True), (datetime.date(2015, 5, 11), datetime.date(2015, 5, 17))) self.assertEqual(pytime.last_week('2015-5-17'), (datetime.date(2015, 5, 4), datetime.date(2015, 5, 12))) self.assertEqual(pytime.last_week('2015-5-17', True), (datetime.date(2015, 5, 4), datetime.date(2015, 5, 11))) self.assertEqual(pytime.next_week('2015-5-17'), (datetime.date(2015, 5, 18), datetime.date(2015, 5, 26))) self.assertEqual(pytime.next_week('2015-5-17', True), (datetime.date(2015, 5, 18), datetime.date(2015, 5, 25))) self.assertEqual(pytime.this_month('2015-5-17'), (datetime.date(2015, 5, 1), datetime.date(2015, 6, 1))) self.assertEqual(pytime.this_month('2015-5-17', True), (datetime.date(2015, 5, 1), datetime.date(2015, 5, 31))) self.assertEqual(pytime.last_month('2015-5-17'), (datetime.date(2015, 4, 1), datetime.date(2015, 5, 1))) self.assertEqual(pytime.last_month('2015-5-17', True), (datetime.date(2015, 4, 1), datetime.date(2015, 4, 30))) self.assertEqual(pytime.next_month('2015-5-17'), (datetime.date(2015, 6, 1), datetime.date(2015, 7, 1))) self.assertEqual(pytime.next_month('2015-5-17', True), (datetime.date(2015, 6, 1), datetime.date(2015, 6, 30))) self.assertTrue(pytime.next_month(1432310400 + gmt8offset, True), (datetime.datetime(2015, 6, 1), datetime.datetime(2015, 6, 30)))
def get_last_run_time(timestamp): yesterday = str(pytime.before(timestamp, '1d')).split(' ')[0] return yesterday