[][src]Struct heca_lib::HebrewYear

pub struct HebrewYear { /* fields omitted */ }

HebrewYear holds data on a given year. It's faster to get multiple HebrewDates from an existing HebrewYear rather than generating each one on its own.

Methods

impl HebrewYear[src]

pub fn new(year: u64) -> Result<HebrewYear, ConversionError>[src]

Returns a new HebrewYear.

Arguments

year - The Hebrew year

pub fn is_leap_year(&self) -> bool[src]

Returns if this year is a leap year.

use heca_lib::HebrewYear;
assert_eq!(HebrewYear::new(5779).unwrap().is_leap_year(),true);

pub fn year_type(&self) -> MonthSchedule[src]

Returns the type of year.

A Hebrew year can be one of 14 combinations of length and starting day.

Returns

A Hebrew Year can be defined by three variables:

  1. The first day of Rosh Hashana - Monday (the second day of the week, represented by Beis - Ba*), Tuesday (the third day of the week, represented by Gimmel - Ga), Thursday (the fifth day of the week, represented by Hei - Ha) and Shabbos (the seventh day of the week, represented by Zayin - Za).
  2. The length of the year, specifically, if Cheshvan and Kislev are both full (Sheleima - 30 days long), empty (Chaseir - 29 days long), or in regular order ("Kesidra", Cheshvan is 29 days long and Kislev is 30. So the year goes 30,29,30,29 etc.).
  3. The day Pesach starts, defined as on Rosh Hashana above.

So, for example, 5779 is a BaShaZ year - that is, the first day of Rosh Hashana was on a Monday (Beis - Ba), Bosh Cheshvan and Kislev are full (Shleimah - Shin), and the first night of Pesach was on Friday night (Zain - Z for Shabbos).

Examples

use heca_lib::HebrewYear;
use heca_lib::prelude::*;
assert_eq!(HebrewYear::new(5779).unwrap().year_type(),MonthSchedule::BaShaZ);

Find out how often does Pesach start on which days:

use heca_lib::HebrewYear;
use heca_lib::prelude::*;
let (mut thu, mut tue, mut sun, mut sat) = (0,0,0,0);
for year in 3765..9999 {
    let t = HebrewYear::new(year).unwrap().year_type();
    match t {
        MonthSchedule::GaChaH
        | MonthSchedule::BaShaH
        | MonthSchedule::BaChaH
        | MonthSchedule::ZaShaH => thu += 1,

        MonthSchedule::HaShaG
        | MonthSchedule::ZaShaG
        | MonthSchedule::ZaChaG
        | MonthSchedule::BaChaG => tue += 1,

        MonthSchedule::HaShA
        | MonthSchedule::ZaChA
        | MonthSchedule::HaChA => sun += 1,
         
        MonthSchedule::HaKaZ
        | MonthSchedule::BaShaZ
        | MonthSchedule::GaKaZ => sat += 1,
    }
}
assert_eq!(thu, 1782);
assert_eq!(tue, 1988);
assert_eq!(sun, 718); // <-- Note, that Pesach falls out on a Motzei Shabbos only 10% of the time.
assert_eq!(sat, 1746);

Find out when will Pesach start on Motzei Shabbos:

use heca_lib::HebrewYear;
use heca_lib::prelude::*;
let mut years: Vec<u64> = Vec::new();
for year in 5780..5880 {
    let t = HebrewYear::new(year).unwrap().year_type();
    match t {
        MonthSchedule::HaShA
        | MonthSchedule::ZaChA
        | MonthSchedule::HaChA => years.push(year),

        _ => { }
         
    }
}
assert_eq!(years, vec![5781, 5785, 5805, 5808, 5812, 5832, 5835, 5839, 5859, 5863] ); // <-- We'll have two of them over the next few years, and then Pesach won't fall out on Motzei Shabbos for twenty years!

pub fn year(&self) -> u64[src]

pub fn get_hebrew_date(
    self,
    month: HebrewMonth,
    day: u8
) -> Result<HebrewDate, ConversionError>
[src]

Returns a HebrewDate from the current year and a supplied month and day.

Arguments:

month - The Hebrew month.

day - The day of the Hebrew month.

pub fn get_holidays(
    &self,
    location: Location,
    yt_types: &[TorahReadingType]
) -> SmallVec<[TorahReadingDay; 256]>
[src]

Returns all the days when the Torah is read.

Arguments

location - Specify if you're looking for the calendar in Israel or in the Diaspora. Is relevent as there's one day of Yom Tov in Israel and two outside. This also affects the Weekly parsha if the last day of Pesach or the second day of Shavuos is on Shabbos, when in Israel we move to the next Parsha while outside we're still reading the Yom Tov reading.

yt_types - An array containing TorahReadingType. This should be used as a flag to specify which types of Torah readings you want to list.

Returns

Returns an array (or a vec) of days.

Note

This may unsorted, and is returned under no defined order.

Examples

extern crate heca_lib;

use heca_lib::prelude::*;
use heca_lib::{HebrewDate, HebrewYear};

let year = HebrewYear::new(5779).unwrap();
let shabbosim = year.get_holidays(Location::Chul, &[TorahReadingType::Shabbos, TorahReadingType::SpecialParsha, TorahReadingType::Chol, TorahReadingType::YomTov]);
let mut count = 0;
for s in shabbosim.into_iter() {
  if s.name() == TorahReading::Shabbos(Parsha::Bereishis) {
    assert_eq!(s.day(), HebrewDate::from_ymd(5779,HebrewMonth::Tishrei, 27).unwrap());
    count += 1;
  }
  else if s.name() == TorahReading::SpecialParsha(SpecialParsha::Zachor) {
    assert_eq!(s.day(), HebrewDate::from_ymd(5779,HebrewMonth::Adar2, 9).unwrap());
    count += 1;
  }
  else if s.name() == TorahReading::Chol(Chol::Chanukah1) {
    assert_eq!(s.day(), HebrewDate::from_ymd(5779,HebrewMonth::Kislev, 25).unwrap());
    count += 1;
  }
  else if s.name() == TorahReading::YomTov(YomTov::Shavuos1) {
    assert_eq!(s.day(), HebrewDate::from_ymd(5779,HebrewMonth::Sivan, 6).unwrap());
    count += 1;
  }
}
assert_eq!(count,4);

Trait Implementations

impl Clone for HebrewYear[src]

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl Copy for HebrewYear[src]

impl Debug for HebrewYear[src]

Auto Trait Implementations

impl Send for HebrewYear

impl Sync for HebrewYear

Blanket Implementations

impl<T> From<T> for T[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]