Skip to main content

Crate pharaonic_hijri

Crate pharaonic_hijri 

Source
Expand description

Hijri (Islamic) calendar dates for jiff: conversion from and to Gregorian dates, calendar math, strftime-style formatting, and Arabic and English month names.

This is the Rust port of php-hijri: the same Gregorian date gives the same Hijri date in both libraries, including the default adjustment of one day back.

use jiff::civil::date;
use pharaonic_hijri::{HijriDate, Language};

let ramadan = HijriDate::from_gregorian(date(2024, 3, 11))?;

assert_eq!(ramadan.to_string(), "1445-09-01");
assert_eq!(ramadan.strftime("%-d %B %Y", Language::Arabic)?, "1 رَمضان 1445");
assert_eq!(ramadan.checked_add_months(1)?.to_gregorian()?, date(2024, 4, 10));

A jiff::Timestamp, such as a database created_at, is an instant with no date of its own. Choose the time zone the date is read in first:

use jiff::{Timestamp, tz::TimeZone};
use pharaonic_hijri::HijriDate;

let created_at: Timestamp = "2024-03-10T23:30:00Z".parse().unwrap();
let riyadh = TimeZone::get("Asia/Riyadh").unwrap();

let hijri = HijriDate::from_gregorian(created_at.to_zoned_datetime(riyadh))?;

assert_eq!(hijri.to_string(), "1445-09-01");

§Features

  • serde: serializes a HijriDate as its YYYY-MM-DD string. Off by default.

Structs§

Converter
Converts between Gregorian and Hijri dates with an adjustment in days.
HijriDate
A date in the Hijri (Islamic) calendar.

Enums§

Error
The error returned when a Hijri date cannot be built, converted, parsed or formatted.
Language
The language of Hijri month names.