doubledate.daysto#

doubledate.daysto(frequency: str, dates=None, *, calendar=None)#

Returns an efficient iterator that yields the number of days to the end of a given frequency.

Parameters:
  • dates (datetime, iterable) – either a date or an iterable of dates

  • calendar (iterable) – custom calendar to use

  • frequency (str) – one of YE, HE, TE, QE, ME, WE

Examples

>>> daysto("ME",datetime.date(2020,2,29))
0
>>> daysto("QE",datetime.date(2020,2,29))
31

>>> dates = [datetime.date(2020,1,1) + datetime.timedelta(i) for i in range(90) if i % 12 != 0]
>>> for date, position in zip(dates, daysto("ME", calendar=dates)):
...     print(date, position)
2020-01-02, 27
2020-01-03, 26
...
2020-02-29,0
2020-03-02,26
...
2020-03-30,0

Notes

Warning

If given a date (rather than a list of dates), the function returns the number of days to the end of the calendar frequency.

Note

The list of dates is assumed to be sorted chronologically (from oldest to most recent), i.e. period changes are detected by comparing two adjacent dates