From a836d1116f9dd70ae5247a9ceafee798d1399abb Mon Sep 17 00:00:00 2001 From: David Schenck Date: Sun, 17 Dec 2023 15:50:38 +0100 Subject: [PATCH] update quickstart --- docs/index.rst | 45 +++++++++++++++++++++++++++++++++++++++++- doubledate/calendar.py | 2 +- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/docs/index.rst b/docs/index.rst index 9509641..a67eaef 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -14,11 +14,54 @@ Installation Quickstart ------------------------------------- -Using doubledate is also easy +Using doubledate is also easy. :: >>> import datetime >>> import doubledate as dtwo + + # load from database, file... + >>> holidays = [ + ... datetime.date(2024, 1, 2), # New Years Day + ... datetime.date(2024, 1,15), # Martin Luther King, Jr. Day + ... datetime.date(2024, 2,19), # Washington's Birthday + ... datetime.date(2024, 3,29), # Good Friday + ... datetime.date(2024, 5,27), # Memorial Day + ... datetime.date(2024, 6,19), # Juneteenth National Independence Day + ... datetime.date(2024, 7, 4), # Independence Day + ... datetime.date(2024, 9, 2), # Labor day + ... datetime.date(2024,11,28), # Thanksgiving Day + ... datetime.date(2024,12,25) # Christmas day + ... ] + + # create a Calendar + # here, every weekday (Mon-Fri), excluding holidys + >>> calendar = dtwo.Calendar.create( + ... "B", + ... starting=dtwo.date(2023, 1, 1), + ... ending=dtwo.date(2023, 12, 31) + ... ).difference(holidays) + + # first business day each month + >>> calendar.resample("M").first() + + # last business day each week + >>> calendar.resample("M").nth(-1) + + # first or last business day dependending on month + >>> calendar.resample("M").apply( + ... lambda month: month[0] if month.start.month < 7 else month[-1] + ... ).combine() + + # most recent date as of given date + >>> calendar.asof(datetime.date(2024, 9, 4), side="left") + datetime.date(2024, 8, 30) + +The library also comes with an additional suite of utility functions +:: + + >>> import datetime + >>> import doubledate as dtwo >>> trade = datetime.date(2020, 6, 17) diff --git a/doubledate/calendar.py b/doubledate/calendar.py index d924b4d..1814e44 100644 --- a/doubledate/calendar.py +++ b/doubledate/calendar.py @@ -140,7 +140,7 @@ def __hash__(self): @classmethod def create( - cls, freq=None, *, starting=None, ending=None, rrule=None, dtype=None, **kwargs + cls, freq="D", *, starting=None, ending=None, rrule=None, dtype=None, **kwargs ): """ Create a new calendar, wrapping :code:`dateutil.rrule`