pharaonic_hijri/lib.rs
1//! Hijri (Islamic) calendar dates for [`jiff`]: conversion from and to
2//! Gregorian dates, calendar math, `strftime`-style formatting, and Arabic and
3//! English month names.
4//!
5//! This is the Rust port of [`php-hijri`](https://github.com/Pharaonic/php-hijri):
6//! the same Gregorian date gives the same Hijri date in both libraries,
7//! including the default adjustment of one day back.
8//!
9//! ```
10//! use jiff::civil::date;
11//! use pharaonic_hijri::{HijriDate, Language};
12//!
13//! let ramadan = HijriDate::from_gregorian(date(2024, 3, 11))?;
14//!
15//! assert_eq!(ramadan.to_string(), "1445-09-01");
16//! assert_eq!(ramadan.strftime("%-d %B %Y", Language::Arabic)?, "1 رَمضان 1445");
17//! assert_eq!(ramadan.checked_add_months(1)?.to_gregorian()?, date(2024, 4, 10));
18//! # Ok::<(), pharaonic_hijri::Error>(())
19//! ```
20//!
21//! A [`jiff::Timestamp`], such as a database `created_at`, is an instant with
22//! no date of its own. Choose the time zone the date is read in first:
23//!
24//! ```
25//! use jiff::{Timestamp, tz::TimeZone};
26//! use pharaonic_hijri::HijriDate;
27//!
28//! let created_at: Timestamp = "2024-03-10T23:30:00Z".parse().unwrap();
29//! let riyadh = TimeZone::get("Asia/Riyadh").unwrap();
30//!
31//! let hijri = HijriDate::from_gregorian(created_at.to_zoned_datetime(riyadh))?;
32//!
33//! assert_eq!(hijri.to_string(), "1445-09-01");
34//! # Ok::<(), pharaonic_hijri::Error>(())
35//! ```
36//!
37//! # Features
38//!
39//! - `serde`: serializes a [`HijriDate`] as its `YYYY-MM-DD` string. Off by
40//! default.
41
42mod calendar;
43mod converter;
44mod date;
45mod error;
46mod language;
47#[cfg(feature = "serde")]
48mod serde;
49mod strftime;
50
51pub use converter::Converter;
52pub use date::HijriDate;
53pub use error::Error;
54pub use language::Language;