Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
mod api
  • Loading branch information
Lalcs committed Jun 26, 2020
1 parent bb5ae32 commit 30b2713
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 27 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -69,7 +69,7 @@ jpholiday.month_holidays(2017, 5)
# 指定範囲の祝日を取得
import jpholiday
import datetime
jpholiday.holidays(datetime.date(2017, 1, 1), datetime.date(2017, 5, 3))
jpholiday.between(datetime.date(2017, 1, 1), datetime.date(2017, 5, 3))
>[(datetime.date(2017, 1, 1), '元日'),
(datetime.date(2017, 1, 2), '元日 振替休日'),
(datetime.date(2017, 1, 9), '成人の日'),
Expand Down
2 changes: 1 addition & 1 deletion jpholiday/__init__.py
Expand Up @@ -11,4 +11,4 @@
2019年 天皇の即位の日及び即位礼正殿の儀の行われる日を休日とする法律
"""

__version__ = '0.1.3'
__version__ = '0.1.4'
44 changes: 20 additions & 24 deletions jpholiday/holiday.py
Expand Up @@ -21,7 +21,7 @@ def _is_holiday_name(self, date):
# 成人の日
class AdultDay(registry.BaseHoliday):
def _is_holiday(self, date):
if date.year <= 1999 and date.month == 1 and date.day == 15:
if date.year in range(1948, 1999 + 1) and date.month == 1 and date.day == 15:
return True
elif date.year >= 2000 and date.month == 1 and date.day == utils._week_day(date, 2, 1).day:
return True
Expand Down Expand Up @@ -83,13 +83,13 @@ def _vernal_equinox_day(year):
if year <= 1948:
return 0

if year >= 1851 and year <= 1899:
if year in range(1851, 1899 + 1):
i = 19.8277
elif year >= 1900 and year <= 1979:
elif year in range(1900, 1979 + 1):
i = 20.8357
elif year >= 1980 and year <= 2099:
elif year in range(1980, 2099 + 1):
i = 20.8431
elif year >= 2100 and year <= 2150:
elif year in range(2100, 1250 + 1):
i = 21.8510
else:
i = 0
Expand All @@ -100,7 +100,7 @@ def _vernal_equinox_day(year):
# みどりの日
class GreeneryDay(registry.BaseHoliday):
def _is_holiday(self, date):
if date.year >= 1989 and date.year <= 2006 and date.month == 4 and date.day == 29:
if date.year in range(1989, 2006 + 1) and date.month == 4 and date.day == 29:
return True
elif date.year >= 2007 and date.month == 5 and date.day == 4:
return True
Expand Down Expand Up @@ -146,11 +146,10 @@ def _is_holiday_name(self, date):
# 海の日
class SeaDay(registry.BaseHoliday):
def _is_holiday(self, date):
if date.year >= 1996 and date.month == 7 and date.year <= 2002 and date.day == 20:
if date.year in range(1996, 2002 + 1) and date.month == 7 and date.day == 20:
return True
# 2020: 国民の祝日に関する法律の一部を改正する法律(平成30年法律第57号)
elif date.year >= 2003 and date.month == 7 and date.year != 2020 and date.day == utils._week_day(date, 3,
1).day:
elif date.year >= 2003 and date.year != 2020 and date.month == 7 and date.day == utils._week_day(date, 3,1).day:
return True

# 2020: 国民の祝日に関する法律(昭和23年法律第178号)の特例
Expand Down Expand Up @@ -184,7 +183,7 @@ def _is_holiday_name(self, date):
# 敬老の日
class RespectForTheAgedDay(registry.BaseHoliday):
def _is_holiday(self, date):
if date.year >= 1966 and date.year <= 2002 and date.month == 9 and date.day == 15:
if date.year in range(1966, 2002 + 1) and date.month == 9 and date.day == 15:
return True
elif date.year >= 2003 and date.month == 9 and date.day == utils._week_day(date, 3, 1).day:
return True
Expand Down Expand Up @@ -216,13 +215,13 @@ def _autumn_equinox_day(year):
if year <= 1948:
return 0

if year >= 1851 and year <= 1899:
if year in range(1851, 1899 + 1):
i = 22.2588
elif year >= 1900 and year <= 1979:
elif year in range(1900, 1979 + 1):
i = 23.2588
elif year >= 1980 and year <= 2099:
elif year in range(1980, 2099 + 1):
i = 23.2488
elif year >= 2100 and year <= 2150:
elif year in range(2100, 2150 + 1):
i = 24.2488
else:
i = 0
Expand All @@ -233,10 +232,9 @@ def _autumn_equinox_day(year):
# 体育の日
class HealthAndSportsDay(registry.BaseHoliday):
def _is_holiday(self, date):
if date.year >= 1966 and date.year <= 1999 and date.month == 10 and date.day == 10:
if date.year in range(1966, 1999 + 1) and date.month == 10 and date.day == 10:
return True
elif date.year >= 2000 and date.year <= 2019 and date.month == 10 and date.day == utils._week_day(date, 2,
1).day:
elif date.year in range(2000, 2019 + 1) and date.month == 10 and date.day == utils._week_day(date, 2, 1).day:
return True
return False

Expand All @@ -247,6 +245,7 @@ def _is_holiday_name(self, date):
# スポーツの日
class SportsDay(registry.BaseHoliday):
def _is_holiday(self, date):

# 2020: 国民の祝日に関する法律の一部を改正する法律(平成30年法律第57号)
# 国民の祝日に関する法律(昭和23年法律第178号)の特例
if date.year >= 2020 and date.year != 2020 and date.month == 10 and date.day == utils._week_day(date, 2, 1).day:
Expand Down Expand Up @@ -368,10 +367,7 @@ def __transfer_holiday_name(self, date):
class NationalHoliday(registry.BaseHoliday):
def _is_holiday(self, date):

result = {
'old': False,
'new': False,
}
result = [False, False]

for holiday in registry.RegistryHolder.get_registry():
if holiday.__class__.__name__ == self.__class__.__name__:
Expand All @@ -381,11 +377,11 @@ def _is_holiday(self, date):
continue

if holiday.is_holiday((date + datetime.timedelta(days=-1))):
result['old'] = True
result[0] = True
if holiday.is_holiday((date + datetime.timedelta(days=1))):
result['new'] = True
result[1] = True

if list(result.values()) == [True, True]:
if result == [True, True]:
return True

return False
Expand Down
10 changes: 9 additions & 1 deletion jpholiday/jpholiday.py
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-

import datetime
import warnings

from . import registry
from . import holiday
Expand Down Expand Up @@ -61,8 +62,15 @@ def month_holidays(year, month):

return output


def holidays(start_date, end_date):
"""
指定された期間の祝日日、祝日名を返します。
"""
warnings.warn("DeprecationWarning: Function 'jpholiday.holidays()' has moved to 'jpholiday.between()' in version '0.1.4' and will be removed in version '0.2'", UserWarning)
return between(start_date, end_date)


def between(start_date, end_date):
"""
指定された期間の祝日日、祝日名を返します。
"""
Expand Down

0 comments on commit 30b2713

Please sign in to comment.