Skip to main content

provides functions to tell if a date is a holiday in Iran or not

Project description

iranholidays is a small python library that provides functions to check if a date is a holiday in Iran or not.

Warning: For Islamic holidays, like Eid al-Fitr, the calculation may be off by a day or two since those events depend on seeing the moon by naked eye and cannot be predicted by computers.

Usage

from iranholidays import holiday_occasion

assert holiday_occasion((2024, 4, 1, 'G')) == 'Sizdah Be-dar'  # Gregorian
assert holiday_occasion((1403, 1, 13, 'S')) == 'Sizdah Be-dar'  # Solar
assert holiday_occasion((1403, 1, 14, 'S')) is None
assert holiday_occasion((1445, 9, 21, 'L')) == 'Martyrdom of Ali'  # Lunar

In case you have a date object from the following libraries, you can check it directly using one of the off_occasion_* functions:

import datetime

import hijri_converter
import jdatetime

from iranholidays import (
    off_occasion_gregorian,
    off_occasion_lunar,
    off_occasion_solar,
)

date = datetime.date(2024, 4, 1)
assert off_occasion_gregorian(date, weekend=()) == 'Sizdah Be-dar'

date = jdatetime.date(1403, 1, 13)
assert off_occasion_solar(date, weekend=()) == 'Sizdah Be-dar'

date = hijri_converter.Hijri(1445, 9, 21)
assert off_occasion_lunar(date, weekend=()) == 'Martyrdom of Ali'

off_occasion function checks if a date is a weekend or holiday and returns the occasion string or None. The default value for weekend parameter is (4,) which means Friday. Either pass a different value to weekend parameter to override it or use set_default_weekend function to change this default for all functions:

from iranholidays import off_occasion, set_default_weekend
date = (2024, 2, 5, 'G')  # a non-holiday Monday
assert off_occasion(date) is None
assert off_occasion(date, weekend=(0,)) == 'Weekend'
set_default_weekend((0,))  # set default weekends to Thursday and Friday
assert off_occasion(date) == 'Weekend'

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

iranholidays-0.2.4.tar.gz (16.3 kB view details)

Uploaded Source

Built Distribution

iranholidays-0.2.4-py3-none-any.whl (16.0 kB view details)

Uploaded Python 3

File details

Details for the file iranholidays-0.2.4.tar.gz.

File metadata

  • Download URL: iranholidays-0.2.4.tar.gz
  • Upload date:
  • Size: 16.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for iranholidays-0.2.4.tar.gz
Algorithm Hash digest
SHA256 c2e2079ecd92b491c0c3bc6cfab959289a89b70eda68d121c552a64c9b09e91d
MD5 72be47035eb59eda5b2a4e011125c8b4
BLAKE2b-256 154c5a888e05bd4e80db5428978d31d63e7b8f4a470e611aa4f76b69241d6b96

See more details on using hashes here.

File details

Details for the file iranholidays-0.2.4-py3-none-any.whl.

File metadata

File hashes

Hashes for iranholidays-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 c30a917c678f1d267de595e7e4e0e49cb1d9a86cbcc2d16c1ddd7976c131d1aa
MD5 33083fd27a7fbab2b677f3e42353b92f
BLAKE2b-256 53f581b3cd5ac393c8e243caaf4500337d70715a428c9d2778010d2fab6799c9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page