#date #conversion #algorithm #gregorian

hijri_date

provides functionality for conversion between hijri and gregorian calander

13 releases

✓ Uses Rust 2018 edition

0.3.2 Jan 12, 2020
0.3.1 Jan 12, 2020
0.2.2 Jan 12, 2020
0.1.6 Aug 6, 2018
Download history 28/week @ 2019-10-16 22/week @ 2019-10-23 14/week @ 2019-10-30 2/week @ 2019-11-06 1/week @ 2019-11-13 14/week @ 2019-11-20 14/week @ 2019-11-27 21/week @ 2019-12-04 128/week @ 2019-12-11 7/week @ 2019-12-25 249/week @ 2020-01-08 28/week @ 2020-01-15

92 downloads per month

MIT license

29KB
420 lines

HijriDate-rs

Documentation

Convert between hijri and gregorian date.

The algorithm used to convert between dates is limited to:

minimum handled hijri year = 1356
maximum handled hijri year = 1499

minimum handled gregorian year = 1938
maximum handled gregorian year = 2076

Usage

convert to 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));

convert to hijri

use hijri_date::HijriDate;

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

hijri day and month name

use hijri_date::HijriDate;

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

compare dates

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);

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 an other 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 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

Credits

I translated the python version https://github.com/tytkal/python-hijiri-ummalqura to rust.

Original algorithm author

Suhail Alkowaileet

Python version author

Khalid Al-hussayen

Chrono

Dependencies

~1MB
~11K SLoC