Skip to content

Commit

Permalink
refactor homepage
Browse files Browse the repository at this point in the history
  • Loading branch information
dschenck committed Dec 18, 2023
1 parent a836d11 commit 8fb0ddc
Showing 1 changed file with 30 additions and 17 deletions.
47 changes: 30 additions & 17 deletions 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

Expand All @@ -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)
<doubledate.calendar.Calendar at 0x17...>

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()
<doubledate.calendar.Calendar at 0x17...>

# last business day each week
>>> calendar.resample("M").nth(-1)
# last business day each week ending on Wednesday
>>> calendar.resample("W-WED").nth(-1)
<doubledate.calendar.Calendar at 0x17...>

# 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()
<doubledate.calendar.Calendar at 0x17...>

# most recent date as of given date
>>> calendar.asof(datetime.date(2024, 9, 4), side="left")
Expand Down

0 comments on commit 8fb0ddc

Please sign in to comment.