doubledate.daysfrom#
- doubledate.daysfrom(frequency: str, dates=None, *, calendar=None)#
Returns an efficient iterator that yields the number of days since the start of a given frequency.
- Parameters:
dates (datetime, iterable, optional) – either a date or an iterable of dates
calendar (iterable) – iterable of dates to use as custom calendar
frequency (str) – one of YS, HS, TS, QS, MS, WS
Notes
Warning
If given a calendar and no dates, the function returns a date-map, mapping each date of the custom calendar to its position within the frequency.
If given a set of dates and no calendar, the function returns the number of days from the generic start of the frequency.
If given a set of dates and a custom calendar, the function returns the number of days since the start of the frequency using the custom calendar as the reference.
Examples
>>> daysfrom(datetime.date(2020,2,29), "MS") 28 >>> daysfrom(datetime.date(2020,2,29), "QS") 59 >>> dates = [datetime.date(2020,1,1) + datetime.timedelta(i) for i in range(90) if i % 12 != 0] >>> for date, position in zip(dates, daysfrom(dates, "MS")): ... print(date, position) 2020-01-02, 0 2020-01-03, 1 ... 2020-02-29,26 2020-03-02,0 ... 2020-03-30,26