Convert dates between the Islamic (Hijri) and Gregorian calendars, in both directions.
Project description
hijri-convert
Convert dates between the Islamic (Hijri) and Gregorian calendars, in both directions, with month names in English and Arabic. Pure Python, zero dependencies.
🌐 Live demo: https://khalidt.github.io/hijri-convert/
Install
pip install hijri-convert
Use it in Python
from hijri_convert import hijri_to_gregorian, gregorian_to_hijri
hijri_to_gregorian(1413, 4, 17)
# (1992, 10, 15, 'Thursday') -> year, month, day, weekday
gregorian_to_hijri(1992, 10, 15)
# (1413, 4, 17, 'Thursday')
Arguments are always in the order year, month, day.
Use it from the command line
After installing, a hijri-convert command is available:
# Hijri -> Gregorian
hijri-convert --to-gregorian 17/04/1413
# Gregorian -> Hijri
hijri-convert --to-hijri 15/10/1992
# Or run with no arguments for an interactive prompt
hijri-convert
Example output:
17/04/1413 AH (17 Rabi al-Thani 1413 / ربيع الآخر)
= Thursday, 15/10/1992 (15 October 1992, Gregorian)
How it works
Conversion goes through the Julian Day Number (JDN), a calendar-neutral day count, so every conversion is just:
Hijri <-> JDN <-> Gregorian
This uses the tabular (arithmetic) Islamic calendar.
API
| Function | Converts | Returns |
|---|---|---|
hijri_to_gregorian(y, m, d) |
Hijri → Gregorian | (year, month, day, weekday) |
gregorian_to_hijri(y, m, d) |
Gregorian → Hijri | (year, month, day, weekday) |
hijri_to_jdn(y, m, d) |
Hijri → Julian Day Number | int |
jdn_to_hijri(jdn) |
Julian Day Number → Hijri | (year, month, day) |
gregorian_to_jdn(y, m, d) |
Gregorian → Julian Day Number | int |
jdn_to_gregorian(jdn) |
Julian Day Number → Gregorian | (year, month, day) |
hijri_month_name(m, arabic=False) |
month number → Hijri name | str |
gregorian_month_name(m) |
month number → Gregorian name | str |
Hijri month names
| # | Name | الاسم | # | Name | الاسم |
|---|---|---|---|---|---|
| 1 | Muharram | المحرّم | 7 | Rajab | رجب |
| 2 | Safar | صفر | 8 | Shaban | شعبان |
| 3 | Rabi al-Awwal | ربيع الأول | 9 | Ramadan | رمضان |
| 4 | Rabi al-Thani | ربيع الآخر | 10 | Shawwal | شوّال |
| 5 | Jumada al-Awwal | جمادى الأولى | 11 | Dhu al-Qidah | ذو القعدة |
| 6 | Jumada al-Thani | جمادى الآخرة | 12 | Dhu al-Hijjah | ذو الحجة |
Accuracy note
This library uses the tabular (arithmetic) Islamic calendar, which is consistent and reversible. Some countries determine month starts by moon sighting or by official almanacs such as Saudi Arabia's Umm al-Qura calendar, so a converted date may differ by ±1 day. For legal, religious, or official use, always check the relevant official calendar.
Development
git clone https://github.com/khalidt/hijri-convert
cd hijri-convert
pip install -e ".[test]"
pytest -v
License
© 2026 Khalid Alkhaldi
This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License (CC BY-NC-SA 4.0).
You are free to share and adapt the material for non-commercial purposes, as
long as you give appropriate credit to Khalid Alkhaldi, link to the license, and
distribute any derivative work under the same license. See the LICENSE
file for the full terms.
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 hijri_convert-1.0.0.tar.gz.
File metadata
- Download URL: hijri_convert-1.0.0.tar.gz
- Upload date:
- Size: 12.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2e4da4d192656a0f892e78e65c890aa1eed46b74f02ea020378c92144bc022e3
|
|
| MD5 |
c47dc8759511be46c17554a16984883e
|
|
| BLAKE2b-256 |
2a1038e1483952ef58ca9ba01a40d0b9c3e7fefff4d560b700ae9cc05f2da929
|
Provenance
The following attestation bundles were made for hijri_convert-1.0.0.tar.gz:
Publisher:
workflow.yml on khalidt/hijri-convert
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hijri_convert-1.0.0.tar.gz -
Subject digest:
2e4da4d192656a0f892e78e65c890aa1eed46b74f02ea020378c92144bc022e3 - Sigstore transparency entry: 1738522797
- Sigstore integration time:
-
Permalink:
khalidt/hijri-convert@50878dbbe0e50ec5a8e96847b095098f44401b6e -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/khalidt
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@50878dbbe0e50ec5a8e96847b095098f44401b6e -
Trigger Event:
push
-
Statement type:
File details
Details for the file hijri_convert-1.0.0-py3-none-any.whl.
File metadata
- Download URL: hijri_convert-1.0.0-py3-none-any.whl
- Upload date:
- Size: 17.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0f585ce6d683dc1b750b934e65af70191f23544105191834f0735fef5f5f7f3f
|
|
| MD5 |
4c35b236e741a451500147343001bf0a
|
|
| BLAKE2b-256 |
7750f88500ed870866e0947e5d4e3ab648400365f6ac8cb3a272ce9464e27c16
|
Provenance
The following attestation bundles were made for hijri_convert-1.0.0-py3-none-any.whl:
Publisher:
workflow.yml on khalidt/hijri-convert
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hijri_convert-1.0.0-py3-none-any.whl -
Subject digest:
0f585ce6d683dc1b750b934e65af70191f23544105191834f0735fef5f5f7f3f - Sigstore transparency entry: 1738522800
- Sigstore integration time:
-
Permalink:
khalidt/hijri-convert@50878dbbe0e50ec5a8e96847b095098f44401b6e -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/khalidt
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@50878dbbe0e50ec5a8e96847b095098f44401b6e -
Trigger Event:
push
-
Statement type: