arrow-py / arrow-py/arrow

Holiday support for Arrow

Open
#913 2 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Python
Stars
9.1k
Forks
784
PR merge metrics
No merged PRs in 30d

Description

## Feature Request

It would be nice to be able to call the following methods on an arrow object:
- `.is_holiday(locale="FI")` to get boolean telling whether the date is a holiday or not
- `.holiday(locale="FI")` to get the name of the holiday (or None if it's not a holiday)

This would be easy to implement using [python-holidays](https://github.com/dr-prodigy/python-holidays). The library includes lots of countries. I would suggest making the dependency optional so that the installation size doesn't increase a lot.

The default value for locale could be read using the current locale of the system. Below is a rough idea translated into code.

```python
try:
import holidays
except ModuleNotFoundError:
holidays = None
import locale

default_locale = locale.getdefaultlocale()[0].split("_")[1]

def is_holiday(arrowobj, locale=None, **kwargs):
if holidays is None:
raise ModuleNotFoundError('Arrow .is_holiday() requires installation of "holidays" package (PyPI holidays)')
holidays_country = getattr(holidays, locale or default_locale)(**kwargs)
return arrowobj.date() in holidays_country

def holiday(arrowobj, locale=None, **kwargs):
if holidays is None:
raise ModuleNotFoundError('Arrow .holiday() requires installation of "holidays" package (PyPI holidays)')
holidays_country = getattr(holidays, locale or default_locale)(**kwargs)
date_ = arrowobj.date()
if date_ in holidays_country:
return holidays_country[date_]
else:
return None
```

In case this feature request gets support, I am willing to code the implementation, so this wouldn't be a burden on the active dev team.

Contributor guide

No contributing guide indexed for this repository

Research direction

No files, tests, or entry points are named. Start by reviewing Arrow's existing public API and conventions for optional dependencies, then determine how the requested methods and system-locale default should fit. Done means holiday detection and names work with python-holidays when installed, and the missing dependency produces the documented error.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.