Skip to content

Commit

Permalink
Merge pull request #5 from dschenck/v0.0.13
Browse files Browse the repository at this point in the history
V0.0.13
  • Loading branch information
dschenck committed Dec 18, 2023
2 parents cb034b5 + e291a5a commit 756c550
Show file tree
Hide file tree
Showing 9 changed files with 333 additions and 180 deletions.
60 changes: 58 additions & 2 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -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,9 +14,65 @@ Installation
Quickstart
-------------------------------------

Using doubledate is also easy
Using doubledate is also easy: simply wrap a list of dates in a :code:`doubledate.Calendar`
::

>>> 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
... ]

# create a Calendar
# here, every weekday (Mon-Fri), excluding holidys
>>> calendar = dtwo.Calendar.create(
... "B",
... 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 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")
datetime.date(2024, 8, 30)

The library also comes with an additional suite of utility functions
::

>>> import datetime
>>> import doubledate as dtwo

Expand Down
4 changes: 4 additions & 0 deletions docs/source/Calendar/doubledate.Calendar.create.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Calendar.create
============================================

.. automethod:: doubledate.Calendar.create
1 change: 1 addition & 0 deletions docs/source/Calendar/doubledate.Calendar.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Calendar

doubledate.Calendar.apply.rst
doubledate.Calendar.asof.rst
doubledate.Calendar.create.rst
doubledate.Calendar.dates.rst
doubledate.Calendar.dayof.rst
doubledate.Calendar.daysbetween.rst
Expand Down
2 changes: 1 addition & 1 deletion doubledate/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.0.12"
__version__ = "0.0.13"

from datetime import MAXYEAR, MINYEAR
from datetime import date, datetime, time, timedelta, timezone, tzinfo
Expand Down
Loading

0 comments on commit 756c550

Please sign in to comment.