Skip to main content

Dates and holidays operations 2.0

A robust, fault-tolerant Python library for date calculations in Robotic Process Automation (RPA).

rpa-dates simplifies complex date arithmetic—especially regarding working days and holidays—ensuring your automation bots never crash due to unexpected calendar edge cases or API outages.

License: MIT Python 3.10+ PyPI Build Status uv Code Style: Ruff Checked with Pyrefly Security: Bandit Robocorp RPA Automation ISO 27001 Compliant ISO 8601 Supported 12-Factor Ready SOLID Principles CUPID Principles

Key Features

  • Resilient Holiday Fetching: Uses a "Chain of Responsibility" fallback strategy.

    1. Local Library (0ms latency, works offline).
    2. Nager.Date API (Primary Web API).
    3. OpenHolidays API (Backup Web API).
  • If one fails, the next one takes over automatically.

  • Production-Grade Working Day Logic:

    • Correctly handles year boundaries (e.g., adding 5 working days to Dec 29th).
    • Preserves time components (e.g., 14:30 remains 14:30).
    • Supports positive and negative offsets.
  • RPA-Friendly: Designed to handle string, date, and datetime inputs interchangeably.

  • Fiscal Year Support: Built-in utilities for fiscal calendars.

Installation

Install using uv (recommended) or pip:

uv add rpa-dates
# OR
pip install rpa-dates

Quick Start

Basic Date Operations

The DateService accepts strings, dates, or datetimes and normalizes them automatically.

from rpa_dates import DateService

ds = DateService()

# Normalizes inputs automatically
dt = ds.normalize("11.02.2025")  # Returns datetime object

# Easy offsets
future_date = ds.offset("01.01.2025", days=10, months=1)
print(future_date)  # 11.02.2025

Working with Business Days

Calculate deadlines accurately by skipping weekends and public holidays.

# Calculate +5 working days from a Friday
# Skips Sat, Sun, and any public holidays found for the country (e.g., 'US')
deadline = ds.working_day_offset(5, "2025-07-03", country_code="US")

print(deadline)
# If July 4th is a holiday, this correctly skips it!

Finding the Nth Working Day

Perfect for "Report is due on the 3rd working day of the month" scenarios.

# Get the 3rd working day of January 2025 in Poland (PL)
report_date = ds.nth_working_day_of_month(3, "2025-01-01", country_code="PL")

print(report_date)
# 2025-01-01 is New Year (Holiday) -> Skip
# 2025-01-02 (Thu) -> 1st WD
# 2025-01-03 (Fri) -> 2nd WD
# 2025-01-04 (Sat) -> Skip
# 2025-01-05 (Sun) -> Skip
# 2025-01-06 (Mon) is Epiphany (Holiday) -> Skip
# 2025-01-07 (Tue) -> 3rd WD (Result)

Configuration

You can customize the service behavior using DateConfig.

from rpa_dates import DateService, DateConfig

config = DateConfig(
    default_input_format='%Y-%m-%d',
    fiscal_year_start_month=10,  # e.g., US Government fiscal year
    api_timeout_seconds=5
)

ds = DateService(config=config)

Architecture: The Provider Fallback

The library guarantees high availability for holiday data using a multi-provider strategy.

  • LocalPythonHolidayProvider: Checks the local holidays Python package. Fast and offline.
  • NagerDateV3Provider: Queries date.nager.at.
  • NagerDateV4Provider: Queries the newer V4 API.
  • OpenHolidaysProvider: Queries openholidaysapi.org.

You don't need to configure this; it happens automatically inside ProviderFactory.

Contributing

I use uv for dependency management.

  1. Clone the repo:

    git clone [https://github.com/21010/rpa-dates.git](https://github.com/21010/rpa-dates.git)
    cd rpa-dates
    
  2. Install dependencies:

    uv sync
    
  3. Run Tests:

    uv run pytest
    

License

This project is licensed under the MIT License - see the LICENSE file for details.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rpa_dates-2.0.3.tar.gz (53.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rpa_dates-2.0.3-py3-none-any.whl (13.4 kB view details)

Uploaded Python 3

File details

Details for the file rpa_dates-2.0.3.tar.gz.

File metadata

  • Download URL: rpa_dates-2.0.3.tar.gz
  • Upload date:
  • Size: 53.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for rpa_dates-2.0.3.tar.gz
Algorithm Hash digest
SHA256 86a76a612e45f13596e974a0b070576390369da76d61f70d08ff48921c608f4f
MD5 2e71a331fb28e1bb502661a3b67c3f53
BLAKE2b-256 0fa5631e68021c363d45673092f8328e724ea6889b70cfba6dd64194ca4308b7

See more details on using hashes here.

File details

Details for the file rpa_dates-2.0.3-py3-none-any.whl.

File metadata

  • Download URL: rpa_dates-2.0.3-py3-none-any.whl
  • Upload date:
  • Size: 13.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for rpa_dates-2.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 3d86f2e11a3d130d680f32f60fa0e1eb51f9cd1d2658750a704be7ecdc1a81dc
MD5 b04cb8a87e2b0a531a9448c0576b8a17
BLAKE2b-256 fd682b0daedb6d47209849892d2c2a926b1717d34bd4d92c42b42a78b042b8f0

See more details on using hashes here.

Release history Release notifications | RSS feed

2.0.4

2 files

This release

2.0.3 This release

2 files

2.0.2

2 files

2.0.1

2 files

2.0.0

2 files

1.0.4

2 files

1.0.3

1 file

1.0.2

2 files

1.0.1

2 files

1.0.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page