Workadays

2023.12.30 · active · verified Thu Apr 16

Workadays is a Python library designed for working with business days, calendar days, and 360-day basis (30/360) date calculations. It allows users to add business days to a given date, check if a specific date is a business day, and retrieve a list of holidays for various countries, states, and provinces. The library had its latest release on December 30, 2023, and generally follows an annual or semi-annual release cadence.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to calculate network days, add working days, and check for holidays using the `workadays` library. It emphasizes the importance of specifying the country for accurate holiday calculations.

import datetime as dt
from workadays import workdays as wd

# Example: Calculate the number of business days between two dates in Brazil
dt_inicio = dt.date(2022, 9, 20)
dt_atual = dt.date(2022, 12, 12)

# You can also pass a list of custom holidays if needed
# holidays = [dt.date(2022, 10, 12), dt.date(2022, 11, 2)]
# n = wd.networkdays(dt_inicio, dt_atual, country='BR', holidays=holidays)

n = wd.networkdays(dt_inicio, dt_atual, country='BR')
print(f"Number of business days between {dt_inicio} and {dt_atual} in Brazil: {n}")

# Example: Add 5 business days to a date
start_date = dt.date(2024, 4, 15)
future_date = wd.add_working_days(start_date, 5, country='US')
print(f"5 business days after {start_date} in the US is: {future_date}")

# Example: Check if a date is a holiday
is_holiday = wd.is_holiday(dt.date(2024, 12, 25), country='US')
print(f"Is December 25, 2024 a holiday in the US? {is_holiday}")

view raw JSON →