time module

date_utilities

py_utilities.time.date_utilities.EPOCH_AS_STRUCT_TIME = time.struct_time(tm_year=1970, tm_mon=1, tm_mday=1, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=3, tm_yday=1, tm_isdst=0)

Epoch represented as a datetime (Thursday, January 1, 1970)

py_utilities.time.date_utilities.is_leap_year(year)[source]

Returns true if the year is a leap year, false otherwise

>>> is_leap_year(2008)
True
>>> is_leap_year(2012)
True
>>> is_leap_year(2013)
False
py_utilities.time.date_utilities.is_weekday(date)[source]

Returns true if date is a weekday, false otherwise

>>> date = datetime.now()
>>> last_friday = date - timedelta(days=date.weekday())     + timedelta(days=4, weeks=-1)
>>> is_weekday(last_friday)
True
py_utilities.time.date_utilities.is_weekend(date)[source]

Returns true if date is a weekend, false otherwise

>>> date = datetime.now()
>>> last_friday = date - timedelta(days=date.weekday())     + timedelta(days=4, weeks=-1)
>>> is_weekend(last_friday)
False
py_utilities.time.date_utilities.next_day(date, day)[source]

Returns the next day (as a datetime) with respect to date. Day parameter is in isoweekday format (Monday 1, Sunday 7).

py_utilities.time.date_utilities.random_datetime(start_timestamp, end_timestamp, tz=None)[source]

Returns a random datetime between two timestamps and converts to the tz if provided