Crate hijri_date
source ·Expand description
HijriDate-rs
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 = 1500
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).unwrap();
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).unwrap();
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).unwrap();
println!("{}",hd.format("%Y %M %D"));
compare dates
use hijri_date::HijriDate;
let hd_1 = HijriDate::from_hijri(1400, 12, 30);
let hd_2 = HijriDate::from_hijri(1357, 1, 1);
assert!(hd_1 > hd_2);
substract duration from a day
use hijri_date::{Duration,HijriDate};
let hd_1 = HijriDate::from_hijri(1420, 06, 15).unwrap();
let hd_2 = HijriDate::from_hijri(1420, 05, 29).unwrap();
assert_eq!(hd_1 - Duration::days(16), hd_2);
substract a day from an other to get a duration
use hijri_date::{Duration,HijriDate};
let hd_1 = HijriDate::from_hijri(1358, 06, 15).unwrap();
let hd_2 = HijriDate::from_hijri(1358, 06, 7).unwrap();
assert_eq!(hd_1-hd_2,Duration::days(8));
Structs
- ISO 8601 time duration with nanosecond precision. This also allows for the negative duration; see individual methods for details.
- Main structure.