hijri_date

Crates.iohijri_date
lib.rshijri_date
version0.5.1
sourcesrc
created_at2018-08-01 17:24:25.337183
updated_at2023-08-16 18:53:00.345723
descriptionprovides functionality for conversion between hijri and gregorian calander (with wasm target)
homepage
repositoryhttps://github.com/sigmaSd/HijriDate-rs
max_upload_size
id76972
size202,487
Bedis Nbiba (sigmaSd)

documentation

README

HijriDate-rs

Released API docs

Convert between hijri and gregorian date. (with wasm target)

Limits

The algorithm used has the following limits:

Minimum Maximum
Hijri 1356 1499
Gregorian 1938 2076

Minimum Rust version

From version 0.4.0 and onwards the MSRV is 1.51

Usage

Conversion

  • Hijri → Gregorian
use hijri_date::HijriDate;

let hd = HijriDate::from_hijri(1439,11,19);
assert_eq!((2018,8,1), (hd.year_gr(), hd.month_gr(), hd.day_gr()));
  • Gregorian → Hijri
use hijri_date::HijriDate;

let hd = HijriDate::from_gr(2000,07,31);
assert_eq!((1421,4,29), (hd.year(), hd.month(), hd.day()));

Comparison

use hijri_date::HijriDate;

let hd_1 = HijriDate::from_hijri(1500, 12, 30);
let hd_2 = HijriDate::from_hijri(1356, 1, 1);
assert!(hd_1 > hd_2);

Misc

  • Subtract duration from a day
use hijri_date::{Duration,HijriDate};

let hd_1 = HijriDate::from_hijri(1420, 06, 15);
let hd_2 = HijriDate::from_hijri(1420, 05, 29);
assert_eq!(hd_1 - Duration::days(16), hd_2);
  • Subtract a day from another to get a duration
use hijri_date::{Duration,HijriDate};

let hd_1 = HijriDate::from_hijri(1356, 06, 15);
let hd_2 = HijriDate::from_hijri(1356, 06, 7);
assert_eq!(hd_1 - hd_2, Duration::days(8));

Formatting

  • Hijri day and month name
use hijri_date::HijriDate;

let hd = HijriDate::from_hijri(1439,11,18);
println!("{}", hd.format("%Y %M %D"));
  • Formatting guide
hijri

%Y              hijri_year
%m              hijri_month
%d              hijri_day
%D              hijri_day_name
%M              hijri_month_name
%l              hijri_month_len

gregorian

%gY             gregorian_year
%gm             gregorian_month
%gd             gregorian_day
%gD             gregorian_day_name
%gM             gregorian_month_name

Wasm

To compile to Wasm run:

 cargo build --release --target wasm32-unknown-unknown

Deno bindings are exposed, see ./deno for more info

Credits

I translated Tytkal's Python library to Rust.

  • Original algorithm author

    Suhail Alkowaileet

  • Python version author

    Khalid Al-hussayen

Chrono

Commit count: 81

cargo fmt