jpholiday


Namejpholiday JSON
Version 0.1.10 PyPI version JSON
download
home_pagehttps://github.com/Lalcs/jpholiday
SummaryPure-Python Japan Public Holiday Generate
upload_time2024-04-23 03:34:48
maintainerNone
docs_urlNone
authorVatis
requires_pythonNone
licenseMIT License
keywords japan holiday
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # JPHoliday

[![image](https://img.shields.io/pypi/v/jpholiday.svg)](https://pypi.org/project/jpholiday/)
[![image](https://img.shields.io/pypi/l/jpholiday.svg)](https://pypi.org/project/jpholiday/)
[![image](https://img.shields.io/pypi/pyversions/jpholiday.svg)](https://pypi.org/project/jpholiday/)
[![image](https://img.shields.io/github/contributors/lalcs/jpholiday.svg)](https://github.com/lalcs/jpholiday/graphs/contributors)
[![image](https://img.shields.io/pypi/dm/jpholiday)](https://pypistats.org/packages/jpholiday)
![Unittest](https://github.com/Lalcs/jpholiday/workflows/Unittest/badge.svg)

日本の祝日を取得するライブラリ

## Installation


```bash
pip install jpholiday
```

## Sample Code
### 指定日の祝日名を取得
```python
import jpholiday
import datetime

# datetime.date
jpholiday.is_holiday_name(datetime.date(2017, 1, 1))
> '元日'
jpholiday.is_holiday_name(datetime.date(2017, 1, 2))
> '元日 振替休日'
jpholiday.is_holiday_name(datetime.date(2017, 1, 3))
> None

# datetime.datetime
jpholiday.is_holiday_name(datetime.datetime(2017, 1, 1, 1, 1, 1))
> '元日'
jpholiday.is_holiday_name(datetime.datetime(2017, 1, 2, 1, 1, 1))
> '元日 振替休日'
jpholiday.is_holiday_name(datetime.datetime(2017, 1, 3, 1, 1, 1))
> None
```

### 指定日が祝日か判定
```python
import jpholiday
import datetime

# datetime.date
jpholiday.is_holiday(datetime.date(2017, 1, 1))
> True
jpholiday.is_holiday(datetime.date(2017, 1, 2))
> True
jpholiday.is_holiday(datetime.date(2017, 1, 3))
> False

# datetime.datetime
jpholiday.is_holiday(datetime.datetime(2017, 1, 1, 1, 1, 1))
> True
jpholiday.is_holiday(datetime.datetime(2017, 1, 2, 1, 1, 1))
> True
jpholiday.is_holiday(datetime.datetime(2017, 1, 3, 1, 1, 1))
> False
```

### 指定年の祝日を取得
```python
import jpholiday
jpholiday.year_holidays(2017)
>[(datetime.date(2017, 1, 1), '元日'),
 (datetime.date(2017, 1, 2), '元日 振替休日'),
 (datetime.date(2017, 1, 9), '成人の日'),
 (datetime.date(2017, 2, 11), '建国記念の日'),
 (datetime.date(2017, 3, 20), '春分の日'),
 (datetime.date(2017, 4, 29), '昭和の日'),
 (datetime.date(2017, 5, 3), '憲法記念日'),
 (datetime.date(2017, 5, 4), 'みどりの日'),
 (datetime.date(2017, 5, 5), 'こどもの日'),
 (datetime.date(2017, 7, 17), '海の日'),
 (datetime.date(2017, 8, 11), '山の日'),
 (datetime.date(2017, 9, 18), '敬老の日'),
 (datetime.date(2017, 9, 23), '秋分の日'),
 (datetime.date(2017, 10, 9), '体育の日'),
 (datetime.date(2017, 11, 3), '文化の日'),
 (datetime.date(2017, 11, 23), '勤労感謝の日'),
 (datetime.date(2017, 12, 23), '天皇誕生日')]
```

### 指定月の祝日を取得
```python
import jpholiday
jpholiday.month_holidays(2017, 5)
>[(datetime.date(2017, 5, 3), '憲法記念日'),
 (datetime.date(2017, 5, 4), 'みどりの日'),
 (datetime.date(2017, 5, 5), 'こどもの日')]
```

### 指定範囲の祝日を取得
```python
import jpholiday
import datetime

# datetime.date
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), '成人の日'),
 (datetime.date(2017, 2, 11), '建国記念の日'),
 (datetime.date(2017, 3, 20), '春分の日'),
 (datetime.date(2017, 4, 29), '昭和の日'),
 (datetime.date(2017, 5, 3), '憲法記念日')]

# datetime.datetime
jpholiday.between(datetime.datetime(2017, 1, 1, 3, 15, 0), datetime.datetime(2017, 5, 3, 12, 30, 12))
>[(datetime.date(2017, 1, 1), '元日'),
 (datetime.date(2017, 1, 2), '元日 振替休日'),
 (datetime.date(2017, 1, 9), '成人の日'),
 (datetime.date(2017, 2, 11), '建国記念の日'),
 (datetime.date(2017, 3, 20), '春分の日'),
 (datetime.date(2017, 4, 29), '昭和の日'),
 (datetime.date(2017, 5, 3), '憲法記念日')]
```

### 独自の休日を追加
```python
import jpholiday
import datetime

class TestHoliday(jpholiday.OriginalHoliday):
    def _is_holiday(self, date):
        if date == datetime.date(2020, 2, 9):
            return True
        return False

    def _is_holiday_name(self, date):
        return '特別休暇'

jpholiday.is_holiday_name(datetime.date(2020, 2, 9))
> '特別休暇'

jpholiday.is_holiday(datetime.date(2020, 2, 9))
> True
```

### 独自の休日を削除
```python
import jpholiday
import datetime

jpholiday.OriginalHoliday.unregister(TestHoliday)
```

## Example

### 独自の休日をファイルから読み込む
```python
import jpholiday
import configparser

class TestHoliday(jpholiday.OriginalHoliday):
    original_holidays = {}

    config = configparser.ConfigParser()
    config.read('holidays.ini')
    if 'HOLIDAYS' in config:
        original_holidays = config['HOLIDAYS']

    def _is_holiday(self, date):
        if date in [datetime.strptime(holiday,'%Y-%m-%d').date() for holiday in self.original_holidays.keys()]:
            return True
        return False

    def _is_holiday_name(self, date):
        if date.strftime('%Y-%m-%d') in self.original_holidays.keys():
            return self.original_holidays[date.strftime('%Y-%m-%d')]
        else:
            return None

'holidays.ini'
[HOLIDAYS]
2021-02-22: 特別休暇1
2021-02-24: 特別休暇2

jpholiday.is_holiday(datetime.date(2021, 2, 22))
> True

jpholiday.is_holiday_name(datetime.date(2021, 2, 22))
> 特別休暇1
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Lalcs/jpholiday",
    "name": "jpholiday",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "Japan, Holiday",
    "author": "Vatis",
    "author_email": "vatis@lalcs.com",
    "download_url": "https://files.pythonhosted.org/packages/e6/6c/df9b06d1287d04ea411bcde4ef086874ea6a622907e3ac6724440fbef628/jpholiday-0.1.10.tar.gz",
    "platform": "POSIX",
    "description": "# JPHoliday\n\n[![image](https://img.shields.io/pypi/v/jpholiday.svg)](https://pypi.org/project/jpholiday/)\n[![image](https://img.shields.io/pypi/l/jpholiday.svg)](https://pypi.org/project/jpholiday/)\n[![image](https://img.shields.io/pypi/pyversions/jpholiday.svg)](https://pypi.org/project/jpholiday/)\n[![image](https://img.shields.io/github/contributors/lalcs/jpholiday.svg)](https://github.com/lalcs/jpholiday/graphs/contributors)\n[![image](https://img.shields.io/pypi/dm/jpholiday)](https://pypistats.org/packages/jpholiday)\n![Unittest](https://github.com/Lalcs/jpholiday/workflows/Unittest/badge.svg)\n\n\u65e5\u672c\u306e\u795d\u65e5\u3092\u53d6\u5f97\u3059\u308b\u30e9\u30a4\u30d6\u30e9\u30ea\n\n## Installation\n\n\n```bash\npip install jpholiday\n```\n\n## Sample Code\n### \u6307\u5b9a\u65e5\u306e\u795d\u65e5\u540d\u3092\u53d6\u5f97\n```python\nimport jpholiday\nimport datetime\n\n# datetime.date\njpholiday.is_holiday_name(datetime.date(2017, 1, 1))\n> '\u5143\u65e5'\njpholiday.is_holiday_name(datetime.date(2017, 1, 2))\n> '\u5143\u65e5 \u632f\u66ff\u4f11\u65e5'\njpholiday.is_holiday_name(datetime.date(2017, 1, 3))\n> None\n\n# datetime.datetime\njpholiday.is_holiday_name(datetime.datetime(2017, 1, 1, 1, 1, 1))\n> '\u5143\u65e5'\njpholiday.is_holiday_name(datetime.datetime(2017, 1, 2, 1, 1, 1))\n> '\u5143\u65e5 \u632f\u66ff\u4f11\u65e5'\njpholiday.is_holiday_name(datetime.datetime(2017, 1, 3, 1, 1, 1))\n> None\n```\n\n### \u6307\u5b9a\u65e5\u304c\u795d\u65e5\u304b\u5224\u5b9a\n```python\nimport jpholiday\nimport datetime\n\n# datetime.date\njpholiday.is_holiday(datetime.date(2017, 1, 1))\n> True\njpholiday.is_holiday(datetime.date(2017, 1, 2))\n> True\njpholiday.is_holiday(datetime.date(2017, 1, 3))\n> False\n\n# datetime.datetime\njpholiday.is_holiday(datetime.datetime(2017, 1, 1, 1, 1, 1))\n> True\njpholiday.is_holiday(datetime.datetime(2017, 1, 2, 1, 1, 1))\n> True\njpholiday.is_holiday(datetime.datetime(2017, 1, 3, 1, 1, 1))\n> False\n```\n\n### \u6307\u5b9a\u5e74\u306e\u795d\u65e5\u3092\u53d6\u5f97\n```python\nimport jpholiday\njpholiday.year_holidays(2017)\n>[(datetime.date(2017, 1, 1), '\u5143\u65e5'),\n (datetime.date(2017, 1, 2), '\u5143\u65e5 \u632f\u66ff\u4f11\u65e5'),\n (datetime.date(2017, 1, 9), '\u6210\u4eba\u306e\u65e5'),\n (datetime.date(2017, 2, 11), '\u5efa\u56fd\u8a18\u5ff5\u306e\u65e5'),\n (datetime.date(2017, 3, 20), '\u6625\u5206\u306e\u65e5'),\n (datetime.date(2017, 4, 29), '\u662d\u548c\u306e\u65e5'),\n (datetime.date(2017, 5, 3), '\u61b2\u6cd5\u8a18\u5ff5\u65e5'),\n (datetime.date(2017, 5, 4), '\u307f\u3069\u308a\u306e\u65e5'),\n (datetime.date(2017, 5, 5), '\u3053\u3069\u3082\u306e\u65e5'),\n (datetime.date(2017, 7, 17), '\u6d77\u306e\u65e5'),\n (datetime.date(2017, 8, 11), '\u5c71\u306e\u65e5'),\n (datetime.date(2017, 9, 18), '\u656c\u8001\u306e\u65e5'),\n (datetime.date(2017, 9, 23), '\u79cb\u5206\u306e\u65e5'),\n (datetime.date(2017, 10, 9), '\u4f53\u80b2\u306e\u65e5'),\n (datetime.date(2017, 11, 3), '\u6587\u5316\u306e\u65e5'),\n (datetime.date(2017, 11, 23), '\u52e4\u52b4\u611f\u8b1d\u306e\u65e5'),\n (datetime.date(2017, 12, 23), '\u5929\u7687\u8a95\u751f\u65e5')]\n```\n\n### \u6307\u5b9a\u6708\u306e\u795d\u65e5\u3092\u53d6\u5f97\n```python\nimport jpholiday\njpholiday.month_holidays(2017, 5)\n>[(datetime.date(2017, 5, 3), '\u61b2\u6cd5\u8a18\u5ff5\u65e5'),\n (datetime.date(2017, 5, 4), '\u307f\u3069\u308a\u306e\u65e5'),\n (datetime.date(2017, 5, 5), '\u3053\u3069\u3082\u306e\u65e5')]\n```\n\n### \u6307\u5b9a\u7bc4\u56f2\u306e\u795d\u65e5\u3092\u53d6\u5f97\n```python\nimport jpholiday\nimport datetime\n\n# datetime.date\njpholiday.between(datetime.date(2017, 1, 1), datetime.date(2017, 5, 3))\n>[(datetime.date(2017, 1, 1), '\u5143\u65e5'),\n (datetime.date(2017, 1, 2), '\u5143\u65e5 \u632f\u66ff\u4f11\u65e5'),\n (datetime.date(2017, 1, 9), '\u6210\u4eba\u306e\u65e5'),\n (datetime.date(2017, 2, 11), '\u5efa\u56fd\u8a18\u5ff5\u306e\u65e5'),\n (datetime.date(2017, 3, 20), '\u6625\u5206\u306e\u65e5'),\n (datetime.date(2017, 4, 29), '\u662d\u548c\u306e\u65e5'),\n (datetime.date(2017, 5, 3), '\u61b2\u6cd5\u8a18\u5ff5\u65e5')]\n\n# datetime.datetime\njpholiday.between(datetime.datetime(2017, 1, 1, 3, 15, 0), datetime.datetime(2017, 5, 3, 12, 30, 12))\n>[(datetime.date(2017, 1, 1), '\u5143\u65e5'),\n (datetime.date(2017, 1, 2), '\u5143\u65e5 \u632f\u66ff\u4f11\u65e5'),\n (datetime.date(2017, 1, 9), '\u6210\u4eba\u306e\u65e5'),\n (datetime.date(2017, 2, 11), '\u5efa\u56fd\u8a18\u5ff5\u306e\u65e5'),\n (datetime.date(2017, 3, 20), '\u6625\u5206\u306e\u65e5'),\n (datetime.date(2017, 4, 29), '\u662d\u548c\u306e\u65e5'),\n (datetime.date(2017, 5, 3), '\u61b2\u6cd5\u8a18\u5ff5\u65e5')]\n```\n\n### \u72ec\u81ea\u306e\u4f11\u65e5\u3092\u8ffd\u52a0\n```python\nimport jpholiday\nimport datetime\n\nclass TestHoliday(jpholiday.OriginalHoliday):\n    def _is_holiday(self, date):\n        if date == datetime.date(2020, 2, 9):\n            return True\n        return False\n\n    def _is_holiday_name(self, date):\n        return '\u7279\u5225\u4f11\u6687'\n\njpholiday.is_holiday_name(datetime.date(2020, 2, 9))\n> '\u7279\u5225\u4f11\u6687'\n\njpholiday.is_holiday(datetime.date(2020, 2, 9))\n> True\n```\n\n### \u72ec\u81ea\u306e\u4f11\u65e5\u3092\u524a\u9664\n```python\nimport jpholiday\nimport datetime\n\njpholiday.OriginalHoliday.unregister(TestHoliday)\n```\n\n## Example\n\n### \u72ec\u81ea\u306e\u4f11\u65e5\u3092\u30d5\u30a1\u30a4\u30eb\u304b\u3089\u8aad\u307f\u8fbc\u3080\n```python\nimport jpholiday\nimport configparser\n\nclass TestHoliday(jpholiday.OriginalHoliday):\n    original_holidays = {}\n\n    config = configparser.ConfigParser()\n    config.read('holidays.ini')\n    if 'HOLIDAYS' in config:\n        original_holidays = config['HOLIDAYS']\n\n    def _is_holiday(self, date):\n        if date in [datetime.strptime(holiday,'%Y-%m-%d').date() for holiday in self.original_holidays.keys()]:\n            return True\n        return False\n\n    def _is_holiday_name(self, date):\n        if date.strftime('%Y-%m-%d') in self.original_holidays.keys():\n            return self.original_holidays[date.strftime('%Y-%m-%d')]\n        else:\n            return None\n\n'holidays.ini'\n[HOLIDAYS]\n2021-02-22: \u7279\u5225\u4f11\u66871\n2021-02-24: \u7279\u5225\u4f11\u66872\n\njpholiday.is_holiday(datetime.date(2021, 2, 22))\n> True\n\njpholiday.is_holiday_name(datetime.date(2021, 2, 22))\n> \u7279\u5225\u4f11\u66871\n```\n",
    "bugtrack_url": null,
    "license": "MIT License",
    "summary": "Pure-Python Japan Public Holiday Generate",
    "version": "0.1.10",
    "project_urls": {
        "Homepage": "https://github.com/Lalcs/jpholiday"
    },
    "split_keywords": [
        "japan",
        " holiday"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "55f8e8c207e24728786a338be3a6739799bb4cc379ed84619f6f28550b7a36d3",
                "md5": "647596cd12e03818deb897bd646d903c",
                "sha256": "2f4bea7380a6cd6dc263e1fec37ea9699e7b7c7e0f6e4a44fe8910d0e1b130ad"
            },
            "downloads": -1,
            "filename": "jpholiday-0.1.10-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "647596cd12e03818deb897bd646d903c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 9809,
            "upload_time": "2024-04-23T03:34:46",
            "upload_time_iso_8601": "2024-04-23T03:34:46.614873Z",
            "url": "https://files.pythonhosted.org/packages/55/f8/e8c207e24728786a338be3a6739799bb4cc379ed84619f6f28550b7a36d3/jpholiday-0.1.10-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e66cdf9b06d1287d04ea411bcde4ef086874ea6a622907e3ac6724440fbef628",
                "md5": "3d256db044e8875207d2fba271063926",
                "sha256": "117895652111138d21353f5686a6eb68c36ccf69ffef4ad9246f7ba801f54cfc"
            },
            "downloads": -1,
            "filename": "jpholiday-0.1.10.tar.gz",
            "has_sig": false,
            "md5_digest": "3d256db044e8875207d2fba271063926",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 15898,
            "upload_time": "2024-04-23T03:34:48",
            "upload_time_iso_8601": "2024-04-23T03:34:48.416515Z",
            "url": "https://files.pythonhosted.org/packages/e6/6c/df9b06d1287d04ea411bcde4ef086874ea6a622907e3ac6724440fbef628/jpholiday-0.1.10.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-23 03:34:48",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Lalcs",
    "github_project": "jpholiday",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "jpholiday"
}
        
Elapsed time: 0.22607s