Skip to content

Commit

Permalink
Merge pull request #1798 from vacanza/dev
Browse files Browse the repository at this point in the history
v0.49
  • Loading branch information
arkid15r committed May 20, 2024
2 parents 55cd302 + 56468c7 commit 89868cf
Show file tree
Hide file tree
Showing 90 changed files with 34,984 additions and 34,414 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ repos:
- rst

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.3
rev: v0.4.4
hooks:
- id: ruff
- id: ruff-format
Expand Down
13 changes: 13 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
Version 0.49
============

Released May 20, 2024

- Refactor Laos holidays (#1797 by @KJhellico)
- Add IFEU holidays (#1792 by @benjfield, @arkid15r)
- Update Hong Kong holidays (#1767 by @KJhellico, @arkid15r)
- Update Malaysia holidays (#1791 by @KJhellico)
- Update observed rules: add holiday removal support (#1796 by @arkid15r)
- Address numpy int argument conversion issue (#1782 by @arkid15r)
- Replace `datetime::timedelta` with custom function (#1785 by @KJhellico)

Version 0.48
============

Expand Down
9 changes: 6 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ All other default values are highlighted with bold:
- HK
-
-
-
- OPTIONAL
* - Hungary
- HU
-
Expand Down Expand Up @@ -602,8 +602,8 @@ All other default values are highlighted with bold:
-
* - Malaysia
- MY
- States: JHR, KDH, KTN, KUL, LBN, MLK, NSN, PHG, PJY, PLS, PNG, PRK, SBH, SGR, SWK, TRG
-
- States and federal territories: 01 (Johor), 02 (Kedah), 03 (Kelantan), 04 (Melaka), 05 (Negeri Sembilan), 06 (Pahang), 07 (Pulau Pinang), 08 (Perak), 09 (Perlis), 10 (Selangor), 11 (Terengganu), 12 (Sabah), 13 (Sarawak), 14 (WP Kuala Lumpur), 15 (WP Labuan), 16 (WP Putrajaya)
- en_US, **ms_MY**
-
* - Maldives
- MV
Expand Down Expand Up @@ -942,6 +942,9 @@ following financial markets are available:
* - European Central Bank
- ECB
- Trans-European Automated Real-time Gross Settlement (TARGET2)
* - ICE Futures Europe
- IFEU
- A London-based Investment Exchange holidays
* - New York Stock Exchange
- XNYS
- NYSE market holidays (used by all other US-exchanges, including NASDAQ, etc.)
Expand Down
1 change: 1 addition & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
examples
contributing
api
mixins
Supported Entities <modules>
changelog
genindex
Expand Down
4 changes: 4 additions & 0 deletions docs/source/mixins.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Mixins
======

.. automodule:: holidays.mixins
2 changes: 1 addition & 1 deletion holidays/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from holidays.registry import EntityLoader
from holidays.utils import *

__version__ = "0.48"
__version__ = "0.49"


EntityLoader.load("countries", globals())
Expand Down
29 changes: 22 additions & 7 deletions holidays/calendars/gregorian.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
# License: MIT (see LICENSE file)

from datetime import date
from datetime import timedelta as td

GREGORIAN_CALENDAR = "GREGORIAN_CALENDAR"

Expand All @@ -30,6 +29,19 @@
WEEKDAYS = {w: i for i, w in enumerate(("mon", "tue", "wed", "thu", "fri", "sat", "sun"))}


# Holiday names.
CHRISTMAS = "christmas"
WINTER_SOLSTICE = "winter_solstice"


def _timedelta(dt: date, days: int = 0) -> date:
"""
Return date that is `days` days after (days > 0) or before (days < 0) specified date.
"""

return date.fromordinal(dt.toordinal() + days)


def _get_nth_weekday_from(n: int, weekday: int, from_dt: date) -> date:
"""
Return date of a n-th weekday before a specific date
Expand All @@ -39,10 +51,13 @@ def _get_nth_weekday_from(n: int, weekday: int, from_dt: date) -> date:
Examples: 1st Monday, 2nd Saturday, etc).
"""

return from_dt + td(
days=(n - 1) * 7 + (weekday - from_dt.weekday()) % 7
if n > 0
else (n + 1) * 7 - (from_dt.weekday() - weekday) % 7
return _timedelta(
from_dt,
(
(n - 1) * 7 + (weekday - from_dt.weekday()) % 7
if n > 0
else (n + 1) * 7 - (from_dt.weekday() - weekday) % 7
),
)


Expand All @@ -61,7 +76,7 @@ def _get_nth_weekday_of_month(n: int, weekday: int, month: int, year: int) -> da
if month > 12:
month = 1
year += 1
start_date = date(year, month, 1) + td(days=-1)
start_date = _timedelta(date(year, month, 1), -1)
else:
start_date = date(year, month, 1)

Expand All @@ -77,4 +92,4 @@ def _get_nth_weekday_of_month(n: int, weekday: int, month: int, year: int) -> da
def _get_all_sundays(year):
first_sunday = _get_nth_weekday_of_month(1, SUN, JAN, year)
for n in range(0, (date(year, DEC, 31) - first_sunday).days + 1, 7):
yield first_sunday + td(days=n)
yield _timedelta(first_sunday, n)
5 changes: 3 additions & 2 deletions holidays/calendars/persian.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
# License: MIT (see LICENSE file)

from datetime import date
from datetime import timedelta as td
from typing import Optional

from holidays.calendars.gregorian import _timedelta


class _Persian:
"""
Expand Down Expand Up @@ -54,4 +55,4 @@ def persian_to_gregorian(self, year: int, j_month: int, j_day: int) -> Optional[

m = j_month - 1
delta = (31 * m if m < 6 else 186 + 30 * (m - 6)) + j_day - 1
return start_date + td(days=delta)
return _timedelta(start_date, delta)
44 changes: 24 additions & 20 deletions holidays/calendars/thai.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
# License: MIT (see LICENSE file)

from datetime import date
from datetime import timedelta as td
from functools import lru_cache
from typing import Optional

from holidays.calendars.gregorian import _timedelta

KHMER_CALENDAR = "KHMER_CALENDAR"
THAI_CALENDAR = "THAI_CALENDAR"

Expand Down Expand Up @@ -230,7 +231,7 @@ def _get_start_date(self, year: int) -> Optional[date]:
elif iter_year in _ThaiLunisolar.ATHIKAWAN_YEARS_GREGORIAN:
delta_days += 1

return _ThaiLunisolar.START_DATE + td(days=delta_days)
return _timedelta(_ThaiLunisolar.START_DATE, delta_days)

def makha_bucha_date(self, year: int, calendar=None) -> Optional[date]:
"""
Expand Down Expand Up @@ -267,13 +268,14 @@ def makha_bucha_date(self, year: int, calendar=None) -> Optional[date]:
if not start_date:
return None

return start_date + td(
days=+102
return _timedelta(
start_date,
+102
if (
year in _ThaiLunisolar.ATHIKAMAT_YEARS_GREGORIAN
and not self.__is_khmer_calendar(calendar)
)
else +73
else +73,
)

def visakha_bucha_date(self, year: int, calendar=None) -> Optional[date]:
Expand Down Expand Up @@ -310,13 +312,14 @@ def visakha_bucha_date(self, year: int, calendar=None) -> Optional[date]:
if not start_date:
return None

return start_date + td(
days=+191
return _timedelta(
start_date,
+191
if (
year in _ThaiLunisolar.ATHIKAMAT_YEARS_GREGORIAN
and not self.__is_khmer_calendar(calendar)
)
else +161
else +161,
)

def preah_neangkoal_date(self, year: int) -> Optional[date]:
Expand Down Expand Up @@ -346,7 +349,7 @@ def preah_neangkoal_date(self, year: int) -> Optional[date]:
if not start_date:
return None

return start_date + td(days=+165)
return _timedelta(start_date, +165)

def atthami_bucha_date(self, year: int, calendar=None) -> Optional[date]:
"""
Expand Down Expand Up @@ -383,13 +386,14 @@ def atthami_bucha_date(self, year: int, calendar=None) -> Optional[date]:
if not start_date:
return None

return start_date + td(
days=+199
return _timedelta(
start_date,
+199
if (
year in _ThaiLunisolar.ATHIKAMAT_YEARS_GREGORIAN
and not self.__is_khmer_calendar(calendar)
)
else +169
else +169,
)

def asarnha_bucha_date(self, year: int) -> Optional[date]:
Expand Down Expand Up @@ -430,7 +434,7 @@ def asarnha_bucha_date(self, year: int) -> Optional[date]:
delta_days = +221
else:
delta_days = +220
return start_date + td(days=delta_days)
return _timedelta(start_date, delta_days)

def khao_phansa_date(self, year: int) -> Optional[date]:
"""
Expand Down Expand Up @@ -469,7 +473,7 @@ def khao_phansa_date(self, year: int) -> Optional[date]:
delta_days = +222
else:
delta_days = +221
return start_date + td(days=delta_days)
return _timedelta(start_date, delta_days)

def boun_haw_khao_padapdin_date(self, year: int) -> Optional[date]:
"""
Expand Down Expand Up @@ -503,7 +507,7 @@ def boun_haw_khao_padapdin_date(self, year: int) -> Optional[date]:
delta_days = +265
else:
delta_days = +264
return start_date + td(days=delta_days)
return _timedelta(start_date, delta_days)

def boun_haw_khao_salark_date(self, year: int) -> Optional[date]:
"""
Expand Down Expand Up @@ -537,7 +541,7 @@ def boun_haw_khao_salark_date(self, year: int) -> Optional[date]:
delta_days = +280
else:
delta_days = +279
return start_date + td(days=delta_days)
return _timedelta(start_date, delta_days)

def pchum_ben_date(self, year: int) -> Optional[date]:
"""
Expand Down Expand Up @@ -571,7 +575,7 @@ def pchum_ben_date(self, year: int) -> Optional[date]:
delta_days = +295
else:
delta_days = +294
return start_date + td(days=delta_days)
return _timedelta(start_date, delta_days)

def ok_phansa_date(self, year: int) -> Optional[date]:
"""
Expand Down Expand Up @@ -605,7 +609,7 @@ def ok_phansa_date(self, year: int) -> Optional[date]:
delta_days = +310
else:
delta_days = +309
return start_date + td(days=delta_days)
return _timedelta(start_date, delta_days)

def boun_suang_heua_date(self, year: int) -> Optional[date]:
"""
Expand Down Expand Up @@ -639,7 +643,7 @@ def boun_suang_heua_date(self, year: int) -> Optional[date]:
delta_days = +311
else:
delta_days = +310
return start_date + td(days=delta_days)
return _timedelta(start_date, delta_days)

def loy_krathong_date(self, year: int) -> Optional[date]:
"""
Expand Down Expand Up @@ -673,4 +677,4 @@ def loy_krathong_date(self, year: int) -> Optional[date]:
delta_days = +339
else:
delta_days = +338
return start_date + td(days=delta_days)
return _timedelta(start_date, delta_days)
4 changes: 2 additions & 2 deletions holidays/countries/angola.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from datetime import date
from gettext import gettext as tr
from typing import Tuple
from typing import Optional, Tuple

from holidays.calendars.gregorian import AUG, SEP
from holidays.groups import ChristianHolidays, InternationalHolidays, StaticHolidays
Expand Down Expand Up @@ -59,7 +59,7 @@ def _is_observed(self, dt: date) -> bool:
# it rolls over to the following Monday.
return dt >= date(1996, SEP, 27)

def _add_observed(self, dt: date, **kwargs) -> Tuple[bool, date]:
def _add_observed(self, dt: date, **kwargs) -> Tuple[bool, Optional[date]]:
# As per Law # #11/18, from 2018/9/10, when public holiday falls on Tuesday or Thursday,
# the Monday or Friday is also a holiday.
kwargs.setdefault(
Expand Down
5 changes: 2 additions & 3 deletions holidays/countries/aruba.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@
# License: MIT (see LICENSE file)

from datetime import date
from datetime import timedelta as td
from gettext import gettext as tr

from holidays.calendars.gregorian import APR, AUG
from holidays.calendars.gregorian import APR, AUG, _timedelta
from holidays.groups import ChristianHolidays, InternationalHolidays
from holidays.holiday_base import HolidayBase

Expand Down Expand Up @@ -118,7 +117,7 @@ def _populate_public_holidays(self):
else:
dt = (AUG, 31)
if self._is_sunday(dt):
dt = date(self._year, *dt) + td(days=-1 if self._year >= 1980 else +1)
dt = _timedelta(date(self._year, *dt), -1 if self._year >= 1980 else +1)
self._add_holiday(name, dt)

# Dia di Labor/Dia di Obrero.
Expand Down
15 changes: 7 additions & 8 deletions holidays/countries/cambodia.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@
# Website: https://github.com/vacanza/python-holidays
# License: MIT (see LICENSE file)

from datetime import timedelta as td
from gettext import gettext as tr

from holidays.calendars.gregorian import MAY, AUG, SEP
from holidays.calendars.gregorian import MAY, AUG, SEP, _timedelta
from holidays.calendars.thai import KHMER_CALENDAR
from holidays.groups import InternationalHolidays, StaticHolidays, ThaiCalendarHolidays
from holidays.holiday_base import HolidayBase
Expand Down Expand Up @@ -98,8 +97,8 @@ def _populate_public_holidays(self):
if self._year in sangkranta_years_apr_14
else self._add_holiday_apr_13(sangkranta)
)
self._add_holiday(sangkranta, dt + td(days=+1))
self._add_holiday(sangkranta, dt + td(days=+2))
self._add_holiday(sangkranta, _timedelta(dt, +1))
self._add_holiday(sangkranta, _timedelta(dt, +2))

# ទិវាពលកម្មអន្តរជាតិ
# Status: In-Use.
Expand Down Expand Up @@ -253,9 +252,9 @@ def _populate_public_holidays(self):
pchum_ben = tr("ពិធីបុណ្យភ្ផុំបិណ្ឌ")
pchum_ben_date = self._add_pchum_ben(pchum_ben)
if pchum_ben_date:
self._add_holiday(pchum_ben, pchum_ben_date + td(days=-1))
self._add_holiday(pchum_ben, _timedelta(pchum_ben_date, -1))
if self._year >= 2017:
self._add_holiday(pchum_ben, pchum_ben_date + td(days=+1))
self._add_holiday(pchum_ben, _timedelta(pchum_ben_date, +1))

# ព្រះរាជពិធីបុណ្យអុំទូក បណ្តែតប្រទីប និងសំពះព្រះខែអកអំបុក
# Status: In-Use.
Expand All @@ -265,8 +264,8 @@ def _populate_public_holidays(self):
bon_om_touk = tr("ព្រះរាជពិធីបុណ្យអុំទូក បណ្តែតប្រទីប និងសំពះព្រះខែអកអំបុក")
bon_om_touk_date = self._add_loy_krathong(bon_om_touk)
if bon_om_touk_date:
self._add_holiday(bon_om_touk, bon_om_touk_date + td(days=-1))
self._add_holiday(bon_om_touk, bon_om_touk_date + td(days=+1))
self._add_holiday(bon_om_touk, _timedelta(bon_om_touk_date, -1))
self._add_holiday(bon_om_touk, _timedelta(bon_om_touk_date, +1))


class KH(Cambodia):
Expand Down

0 comments on commit 89868cf

Please sign in to comment.