From 8fb0ddc06793a1b46182c95187f7de16ac284ab7 Mon Sep 17 00:00:00 2001 From: David Schenck Date: Mon, 18 Dec 2023 07:39:00 +0100 Subject: [PATCH] refactor homepage --- docs/index.rst | 47 ++++++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/docs/index.rst b/docs/index.rst index a67eaef..dc19d94 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -1,6 +1,6 @@ doubledate ===================================== -**doubledate** exposes a set of 20+ utility functions as well as an immutable :code:`Calendar` object representing a sorted-set of dates. +**doubledate** exposes an immutable :code:`Calendar` object representing a sorted-set of dates as well as a suite of 20+ utility functions. .. include:: fragments/badges.rst @@ -14,44 +14,57 @@ Installation Quickstart ------------------------------------- -Using doubledate is also easy. +Using doubledate is also easy: simply wrap a list of dates in a :code:`doubledate.Calendar` :: - >>> import datetime >>> import doubledate as dtwo + >>> dates = [...] # list of dates + >>> calendar = dtwo.Calendar(dates) + + +More realistically: + +:: + + >>> 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 + ... 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) + ... starting=dtwo.date(2024, 1, 1), + ... ending=dtwo.date(2024, 12, 31) ... ).difference(holidays) # first business day each month >>> calendar.resample("M").first() + - # last business day each week - >>> calendar.resample("M").nth(-1) + # last business day each week ending on Wednesday + >>> calendar.resample("W-WED").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")