A set of functions related with dates
Install via pip
pip install t77_dateA set of datetime.datetime and datetime.date related functions.
Return a new datetime.datetime object with values that represent a start of a day.
Example
>>> dt = datetime(2016, 7, 2, 21, 49, 12)
>>> sod = start_of_day(dt)
>>> print(sod)
2016-07-02 00:00:00Return a new datetime.datetime object with values that represent a end of a day.
Example
>>> dt = datetime(2016, 7, 2, 21, 49, 12)
>>> eod = end_of_day(now)
>>> print(eod)
2016-07-02 23:59:59.999999Return a new datetime.datetime object with values that represent a start of a month.
Example
>>> dt = datetime(2016, 7, 2, 21, 49, 12)
>>> som = start_of_month(dt)
>>> print(som)
2016-07-01 00:00:00Return a new datetime.datetime object with values that represent a end of a month.
Example
>>> dt = datetime(2016, 7, 2, 21, 49, 12)
>>> eom = end_of_day(now)
>>> print(eom)
2016-07-31 23:59:59.999999Set week day. New date will be greater or equal than input date.
Example
>>> saturday = datetime(2016, 7, 2, 21, 49, 12)
>>> next_friday = set_next_week_day(saturday, ISO_FRIDAY, iso=True)
>>> print(next_friday)
2016-07-08 21:49:12
>>> next_friday = set_next_week_day(saturday, FRIDAY, iso=False)
>>> print(next_friday)
2016-07-08 21:49:12Set week day. New date will be less or equal than input date.
Example
>>> saturday = datetime(2016, 7, 2, 12)
>>> prev_friday = set_prev_week_day(saturday, ISO_FRIDAY, iso=True)
>>> print(prev_friday)
2016-07-01 21:49:12
>>> prev_friday = set_prev_week_day(saturday, FRIDAY, iso=False)
>>> print(prev_friday)
2016-07-01 21:49:12A set of datetime.time related functions.
Calculates datetime.timedelta between two datetime.time values.
Example
>>> t1, t2 = time(hour=1), time(hour=2)
>>> print(diff_time(t2, t1))
1:00:00
>>> print(diff_time(t1, t2))
-1 day, 23:00:00A set of datetime.timedelta related functions.
Convert datetime.timedelta to seconds.
Example
>>> td = timedelta(days=1, microseconds=1)
>>> seconds = timedelta_to_seconds(td)
>>> print(seconds)
86400
>>> seconds = timedelta_to_seconds(td, with_microseconds=True)
>>> print(seconds)
86400.000001String representation of datetime.timedelta.
Example
>>> td = timedelta(days=5, microseconds=1)
>>> td_str = timedelta_to_str(td)
>>> print(td_str)
'120:00:00'
>>> td_str = timedelta_to_str(val, with_microseconds=True)
>>> print(td_str)
'120:00:00.000001'Parses a string and return a datetime.timedelta.
Example
>>> value = '1:11:12.13'
>>> td = parse_timedelta(value)
>>> print(td)
1:11:12.000013
>>> value = '1 day, 10:11:12.13'
>>> td = parse_timedelta(value)
>>> print(td)
1 day, 1:11:12.000013A set of dateutil.tz related functions.
Convert datetime.datetime to UTC.
Example
>>> d1 = datetime.now(tz=tzlocal())
>>> d2 = to_utc(d1)
>>> print(d1)
2017-02-20 13:19:36.511822+01:00
>>> print(d2)
2017-02-20 12:19:36.511822+00:00Convert datetime.datetime to local time zone.
Example
>>> d1 = datetime.now(tz=tzutc())
>>> d2 = to_local(d1)
>>> print(d1)
2017-02-20 12:19:36.511822+00:00
>>> print(d2)
2017-02-20 13:19:36.511822+01:00