def test_time_before_1(): a = date_now() time.sleep(1) b = date_now() time.sleep(1) assert time_before(a, b) assert not time_before(b, a) assert time_before(a) assert time_before(b)
def test_time_after_1(): a = date_now() time.sleep(1) b = date_now() time.sleep(1) assert time_after(b, a) assert not time_after(a, b) assert not time_after(a) assert not time_after(b)
def test_date_convert_to_timezone_1(): now = date_now(utc=True) assert now.tzinfo is not None utc_date = date_convert_to_timezone(now, 'utc') # make sure the hour is not changed when making the date timezone aware assert utc_date.hour == now.hour assert utc_date.tzinfo is not None now = date_now() pst_timezone_date = date_convert_to_timezone(now, 'America/Los_Angeles') # make sure the hour is changed when making the date timezone aware assert pst_timezone_date.hour != now.hour assert pst_timezone_date.tzinfo is not None
def test_epoch_time_now_1(): epoch_now = epoch_time_now() standardized_date = epoch_to_date(epoch_now) now = date_now() assert standardized_date.year == now.year assert standardized_date.month == now.month assert standardized_date.day == now.day
def test_date_make_timezone_aware_1(): now = date_now() assert now.tzinfo is None timezone_aware_datetime = date_make_timezone_aware(now) # make sure the hour is not changed when making the date timezone aware assert timezone_aware_datetime.hour == now.hour assert timezone_aware_datetime.tzinfo is not None utc_timezone_date = date_make_timezone_aware(now, timezone_string='utc') assert utc_timezone_date.hour == now.hour pst_timezone_date = date_make_timezone_aware( now, timezone_string='America/Los_Angeles') assert pst_timezone_date.hour == now.hour
def test_date_to_epoch_1(): assert isinstance(date_to_epoch(date_now()), int) assert float(date_to_epoch(date_now())) > 1540000000 assert date_to_epoch('January 1, 2010') < date_to_epoch('January 1, 2011')
def test_date_now_convert_timezone(): a = date_now() assert '+00:00' not in str(a) a = date_now(convert_to_current_timezone=True) assert '+00:00' in str(a)
def test_date_now_1(): a = date_now() b = date_now() assert a < b
def test_date_parse_1(): standardized_date = date_parse('2019/12/13') assert standardized_date.year == 2019 assert standardized_date.month == 12 assert standardized_date.day == 13 # find yesterday's date using the date standardization function standardized_date = date_parse('yesterday') # find yesterday's date using another function so that we can compare the two yesterday = date_now() - datetime.timedelta(days=1) assert standardized_date.year == yesterday.year assert standardized_date.month == yesterday.month assert standardized_date.day == yesterday.day # find a previous date using the date standardization function standardized_date = date_parse('3 days ago') # find a previous date using another function so that we can compare the two past_date = date_now() - datetime.timedelta(days=3) assert standardized_date.year == past_date.year assert standardized_date.month == past_date.month assert standardized_date.day == past_date.day # find a future date using the date standardization function standardized_date = date_parse('3 days from now') # find a previous date using another function so that we can compare the two future_date = date_now() + datetime.timedelta(days=3) assert standardized_date.year == future_date.year assert standardized_date.month == future_date.month assert standardized_date.day == future_date.day standardized_date = date_parse('Sat Oct 11 17:13:46 -1 2003') assert standardized_date.year == 2003 assert standardized_date.month == 10 assert standardized_date.day == 11 assert standardized_date.hour == 17 assert standardized_date.minute == 13 # test the same date as above, but convert the time to the current timezone (which is assumed to be UTC) standardized_date = date_parse('Sat Oct 11 17:13:46 -1 2003', convert_to_current_timezone=True) assert standardized_date.hour == 18 standardized_date = date_parse('Sat, Oct 11, 2003') assert standardized_date.year == 2003 assert standardized_date.month == 10 assert standardized_date.day == 11 standardized_date = date_parse('1564765879') assert standardized_date.year == 2019 assert standardized_date.month == 8 assert standardized_date.day == 2 standardized_date = date_parse('1564765879000') assert standardized_date.year == 2019 assert standardized_date.month == 8 assert standardized_date.day == 2 standardized_date = date_parse('1564765879000000') assert standardized_date.year == 2019 assert standardized_date.month == 8 assert standardized_date.day == 2 standardized_date = date_parse('last friday') today = date_now() diff = today - standardized_date assert diff.days <= 7 standardized_date = date_parse('2018-11-08T16:52:42Z') assert standardized_date.year == 2018 assert standardized_date.month == 11 assert standardized_date.day == 8 standardized_date = date_parse('2019 12 25') assert standardized_date.year == 2019 assert standardized_date.month == 12 assert standardized_date.day == 25 standardized_date = date_parse('1564765879.3141592') assert standardized_date.year == 2019 assert standardized_date.month == 8 assert standardized_date.day == 2 standardized_date = date_parse('2018-11-08T22:52:42-05:00') assert standardized_date.year == 2018 assert standardized_date.month == 11 assert standardized_date.day == 8 # this is the same date as above, but convert the time to the current timezone (which is assumed to be UTC) standardized_date = date_parse('2018-11-08T22:52:42-05:00', convert_to_current_timezone=True) # the day should be the next day UTC assert standardized_date.day == 9 standardized_date = date_parse('2018-01-13T11:11:11Z') assert standardized_date.year == 2018 assert standardized_date.month == 1 assert standardized_date.day == 13 assert standardized_date.hour == 11 assert standardized_date.minute == 11 assert str(standardized_date) == '2018-01-13 11:11:11+00:00'