heca_lib/lib.rs
1//! # heca-lib
2//! heca-lib is a blazingly fast Hebrew calender library. It's the backend behind the heca program.
3//!
4//! # Usage:
5//!
6//! 1. Add to Cargo.toml:
7//!
8//!```toml
9//! [dependencies]
10//! heca-lib = "1.3"
11//!```
12//!
13//! 2. Add the following to your crate root:
14//!
15//! ```
16//! extern crate heca_lib;
17//!
18//! ```
19//! 3. Import the types:
20//!
21//!```
22//!use heca_lib::prelude::*;
23//!use heca_lib::*;
24//!```
25//!
26//! # Overview:
27//!
28//! ## Convert:
29//!
30//! This library can convert from Hebrew to Gregorian dates and back. You can get a HebrewDate either from a known Hebrew date or from a Gregorian date:
31//!
32//! ```
33//!
34//! use std::num::NonZeroI8;
35//! use std::convert::TryInto;
36//!
37//! use chrono::Utc;
38//! use chrono::offset::TimeZone;
39//! use heca_lib::prelude::*;
40//! use heca_lib::HebrewDate;
41//!
42//!
43//! let hebrew_date: HebrewDate = Utc.ymd(2018,9,10).and_hms(17,59,59).try_into()?;
44//! assert_eq!(hebrew_date,HebrewDate::from_ymd(5779,HebrewMonth::Tishrei,NonZeroI8::new(1).unwrap())?);
45//! # Ok::<(),ConversionError>(())
46//!
47//!```
48//!
49//!You can then get back a Gregorian date from this Hebrew Date.
50//!
51//!```
52//!
53//! use std::num::NonZeroI8;
54//! use std::convert::TryInto;
55//!
56//! use chrono::prelude::*;
57//! use heca_lib::{HebrewDate};
58//! use heca_lib::prelude::*;
59//!
60//! let eng_day: DateTime<Utc> = HebrewDate::from_ymd(5779,HebrewMonth::Tishrei,NonZeroI8::new(10).unwrap())?.into();
61//! assert_eq!(eng_day, Utc.ymd(2018, 9,18).and_hms(18,00,00));
62//! # Ok::<(),ConversionError>(())
63//!
64//!```
65//!
66//! ## Get Information on the Hebrew Year
67//!
68//! This library can also list the major Jewish holidays and Torah readings in a given year (for
69//! both Israel and the Diaspora):
70//!
71//!```
72//!
73//!use std::num::NonZeroI8;
74//!
75//!use heca_lib::{HebrewYear,HebrewDate};
76//!use heca_lib::prelude::*;
77//!
78//!assert_eq!(HebrewYear::new(5779)?.get_holidays(Location::Chul, &[TorahReadingType::Shabbos])[0].name(), TorahReading::Shabbos(Parsha::Vayelech));
79//!assert_eq!(HebrewYear::new(5779)?.get_holidays(Location::Chul, &[TorahReadingType::SpecialParsha]).iter().find(|x| x.name() == TorahReading::SpecialParsha(SpecialParsha::Zachor)).unwrap().day(),HebrewDate::from_ymd(5779,HebrewMonth::Adar2,NonZeroI8::new(9).unwrap())?);
80//!# Ok::<(),ConversionError>(())
81//!
82//!```
83//!
84//!
85//!# Notes:
86//!
87//!This library won't work for years before 3764 (4).
88
89#[macro_use]
90extern crate lazy_static;
91mod convert;
92mod holidays;
93pub mod prelude;
94#[doc(inline)]
95pub use convert::HebrewDate;
96#[doc(inline)]
97pub use convert::HebrewYear;