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 is_holiday

assert is_holiday((2024, 4, 1, 'G')) == 'Sizdah Be-dar'  # Gregorian
assert is_holiday((1403, 1, 13, 'S')) == 'Sizdah Be-dar'  # Solar
assert is_holiday((1403, 1, 14, 'S')) is False
assert is_holiday((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 is_workday_* functions:

import datetime

import hijri_converter
import jdatetime

from iranholidays import (
    is_workday_gregorian,
    is_workday_lunar,
    is_workday_solar,
)

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

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

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

is_workday function checks if a date is a weekend and returns True or the occasion string. 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 the default:

from iranholidays import is_workday, set_default_weekend
date = (2024, 2, 5, 'G')  # a non-holiday Monday
assert is_workday(date) is True
assert is_workday(date, weekend=(0,)) == 'Weekend'
set_default_weekend((0,))  # set default weekends to Thursday and Friday
assert is_workday(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.1.0.tar.gz (8.2 kB view hashes)

Uploaded Source

Built Distribution

iranholidays-0.1.0-py3-none-any.whl (7.9 kB view hashes)

Uploaded Python 3

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