hevslib.time module

Time functions

hevslib.time.getFirstDom(any_day)

Get datetime object of first day of month of given day

Parameters

any_day – datetime of a day in the month

Returns

datetime object of first day of month

hevslib.time.getLastDom(any_day)

Get datetime object of last day of month of given day

Parameters

any_day – datetime of a day in the month

Returns

datetime object of last day of month

hevslib.time.getMonth(addMonth=0, date=None)

Get start and end of month

Parameters
  • addMonth – int to jump back and ahead of given month or current month

  • date – datetime of a day in the month

Returns

list of datetime object of first and last day of month

hevslib.time.getTodayDate()

Get current date in datetime format

Returns

datetime object

hevslib.time.getWeek(addWeek=0, date=None)

Get start and end of week

Parameters
  • addWeek – int to jump back and ahead of given week or current week

  • date – datetime of a day in the week

Returns

list of datetime object of first and last day of month

hevslib.time.getWeekNbr(date=None)

Get number of week of give date

Parameters

date – datetime of a day in the week

Returns

list of datetime object of first and last day of month

hevslib.time.getYear(addYear=0, date=None)

Get start and end of year

Parameters
  • addYear – int to jump back and ahead of given year or current year

  • date – datetime of a day in the year

Returns

list of datetime object of first and last day of year

hevslib.time.strfdelta(tdelta, fmt='{D:02}d {H:02}h {M:02}m {S:02}s', inputtype='timedelta')

Convert a datetime.timedelta object or a regular number to a custom- formatted string, just like the stftime() method does for datetime.datetime objects.

The fmt argument allows custom formatting to be specified. Fields can include seconds, minutes, hours, days, and weeks. Each field is optional.

Some examples:

‘{D:02}d {H:02}h {M:02}m {S:02}s’ –> ‘05d 08h 04m 02s’ (default) ‘{W}w {D}d {H}:{M:02}:{S:02}’ –> ‘4w 5d 8:04:02’ ‘{D:2}d {H:2}:{M:02}:{S:02}’ –> ‘ 5d 8:04:02’ ‘{H}h {S}s’ –> ‘72h 800s’

The inputtype argument allows tdelta to be a regular number instead of the default, which is a datetime.timedelta object. Valid inputtype strings:

‘s’, ‘seconds’, ‘m’, ‘minutes’, ‘h’, ‘hours’, ‘d’, ‘days’, ‘w’, ‘weeks’

Parameters
  • tdelta – timedelta64 format

  • fmt – string for formatting see examples

  • inputtype – string ‘timedelta’, ‘s’, ‘m’, ‘h’, ‘d’, ‘w’

Returns

Timedelta in string format

hevslib.time.sumTwoDatetime(baseDateTime, toAddDateTime)

Sum two DateTime, aware (and taking account) of any overflow in second/minute/hour/day/month/year.

Parameters
  • baseDateTime (DateTime) – Reference DateTime.

  • toAddDateTime (DateTime) – DateTime to add.

Returns

Return an updated DateTime.

Return type

DateTime