Japanese holiday detection library based on Cabinet Office data, ported from holiday-jp-npm.
Project description
holiday-jp-pip
内閣府ホームページの「国民の祝日」についてに基づいて平日や祝日を判定する Python ライブラリです。 独自の祝日を追加することも可能です。
JS 版 @sway11466/holiday-jp-npm の Python 移植版です。
-
判定ルール
日付の種類 判定方法 平日 週末でも祝日でもない日 週末 土曜日および日曜日(対象となる曜日は設定で変更可能) 祝日 内閣府ホームページの「国民の祝日」についてに記載の祝日 -
判定の例(2024年5月)
日付の種類 5/1(水) 5/2(木) 5/3(金) 5/4(土) 5/5(日) 5/6(月) 5/7(火) 平日 〇 〇 × × × × 〇 週末 × × × 〇 〇 × × 祝日 × × 〇 〇 〇 〇 ×
インストール
pip install holiday-jp-pip
使い方
-
初期化
from holiday_jp import HolidayJP holidayjp = HolidayJP()
-
指定日が祝日であるか判定する
from datetime import date ret = holidayjp.is_holiday(date(2021, 5, 3)) # 2021/5/3 憲法記念日 print(ret) # True
-
指定日が平日であるか判定する
ret = holidayjp.is_weekday(date(2021, 5, 7)) # 2021/5/7 平日 print(ret) # True
-
指定した条件に当てはまる祝日を取得する(例 1)
holidays = holidayjp.get(year=2021, month=5) print(len(holidays)) # 3 print(holidays[0].name) # 憲法記念日 print(holidays[0].local_date) # 2021-05-03 00:00:00+09:00 (JST 0:00 の datetime)
-
指定した条件に当てはまる祝日を取得する(例 2)
holidays = holidayjp.get(year=2021, name="スポーツの日") print(len(holidays)) # 1 print(holidays[0].local_date) # 2021-07-23 00:00:00+09:00 print(holidays[0].local_date.astimezone().date()) # 実行環境 TZ で見た日付
-
独自の祝日を追加する
from datetime import date, datetime from holiday_jp import HolidayJP, Holiday, JST additional = [Holiday(year=2023, month=3, date=10, name="test", local_date=datetime(2023, 3, 10, tzinfo=JST))] holidayjp = HolidayJP(extends=additional) ret = holidayjp.is_holiday(date(2023, 3, 10)) print(ret) # True
説明
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file holiday_jp_pip-0.2.0.tar.gz.
File metadata
- Download URL: holiday_jp_pip-0.2.0.tar.gz
- Upload date:
- Size: 11.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.9 {"installer":{"name":"uv","version":"0.11.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
12b5bc86e48a477f1173a22e9557f5f88fd9644b9d5700e812670c70397dcbe7
|
|
| MD5 |
1e03d4268b271d5f63f70e6fa10570dc
|
|
| BLAKE2b-256 |
ca5f03ede64203da68ec7032f3350bf2344a40a2b7673f5701398757c71bd5be
|
File details
Details for the file holiday_jp_pip-0.2.0-py3-none-any.whl.
File metadata
- Download URL: holiday_jp_pip-0.2.0-py3-none-any.whl
- Upload date:
- Size: 12.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.9 {"installer":{"name":"uv","version":"0.11.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6e1e5b8c74520897d6713cfc4028e930cb9d47c0fb69a27cbf8e1817147cb6d1
|
|
| MD5 |
c6ba9aa789825401d3044947690880fc
|
|
| BLAKE2b-256 |
e0f7d1544d881e0d8787de1dd67fc8ab73916627e33ce7144328449176b57daf
|