Holiday support for Arrow
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. 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.
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.
Hi @b10011 apologies for never getting back to you on this! @systemcatch what are your thoughts on this? Do you think it is worth introducing the hard holiday dependency to Arrow? It seems actively maintained, so it might be a cool feature addition.
@jadchaar reading through the holidays module (which is a very neat idea) it seems easy to feed in dates/strings from arrow already, I'm not sure adding a dependency gains much here.