[][src]Struct heca_lib::HebrewDate

pub struct HebrewDate { /* fields omitted */ }

Methods

impl HebrewDate[src]

pub fn from_ymd(
    year: u64,
    month: HebrewMonth,
    day: u8
) -> Result<HebrewDate, ConversionError>
[src]

Returns a HebrewDate on success, or a ConversionError on failure.

Arguments

  • year - The Hebrew year since creation.
  • month - The Hebrew month.
  • day - The Hebrew day of month.

Error Values

  • YearTooSmall - This algorithm won't work if the year is before 3764.
  • DayIsZero - Months start with day 1, not zero. So 0 Adar won't work.
  • IsLeapYear - I treat Adar, Adar 1 and Adar 2 as three seperate months, so if you want to convert a day in Adar 1 or Adar 2 of a leap year, specify which one.
  • IsNotLeapYear - I treat Adar, Adar 1 and Adar 2 as three seperate months, so it won't make sense to get the English date of the first of Adar 1 or Adar 2 if the year isn't a leap year.
  • TooManyDaysInMonth - There are either 29 or 30 days in a month, so it doesn't make sense to find the 50th day of Nissan.

pub fn from_gregorian(
    date: DateTime<Utc>
) -> Result<HebrewDate, ConversionError>
[src]

Returns a HebrewDate on success, or a ConversionError on failure.

Arguments

  • date - The Gregorian date.

Notes:

Hebrew days start at sundown, not midnight, so there isn't a full 1:1 mapping between Gregorian days and Hebrew. So when you look up the date of Rosh Hashana 5779, you'll get "Monday, 10th of September 2018", while Rosh Hashana really started at sundown on the 9th of September.

I'm trying to be a bit more precise, so I made the date cutoff at 6:00 PM. So for example:

extern crate heca_lib;

use chrono::Utc;
use chrono::offset::TimeZone;
use heca_lib::prelude::*;
use heca_lib::HebrewDate;

assert_eq!(HebrewDate::from_gregorian(Utc.ymd(2018,9,10).and_hms(17,59,59)).unwrap(),HebrewDate::from_ymd(5779,HebrewMonth::Tishrei,1).unwrap());

while

extern crate heca_lib;

use chrono::Utc;
use chrono::offset::TimeZone;
use heca_lib::prelude::*;
use heca_lib::HebrewDate;

assert_eq!(HebrewDate::from_gregorian(Utc.ymd(2018,9,10).and_hms(18,0,0)).unwrap(),HebrewDate::from_ymd(5779,HebrewMonth::Tishrei,2).unwrap());

Error Values:

  • YearTooSmall - This algorithm won't work if the year is before roughly year 4.

pub fn to_gregorian(&self) -> DateTime<Utc>[src]

Gets the Gregorian date for the current Hebrew date.

Notes

This function returns the DateTime of the given HebrewDate at nightfall.

For example, Yom Kippur 5779 started at sunset of September 18, 2018. So

extern crate heca_lib;

use chrono::Utc;
use chrono::offset::TimeZone;
use heca_lib::prelude::*;
use heca_lib::HebrewDate;

assert_eq!(HebrewDate::from_ymd(5779,HebrewMonth::Tishrei,10).unwrap().to_gregorian(),Utc.ymd(2018, 9,18).and_hms(18,00,00));

Algorithm:

The conversion is done (at the moment) according to the calculation of the Rambam (Maimonidies), as is documented in Hilchos Kiddush Ha'chodesh.

The algorithm is as follows:

  1. There are exactly 1080 Chalakim (parts) in an hour.
  2. There are exactly (well, not really. But it's close enough that we use that number as exact.) 29 days, 12 hours, and 793 Chalakim between new moons.

So that's the basic numbers. Regarding the calendar itself:

  1. All months are either 29 or 30 days long.
  2. There are either 12 or 13 months in the Hebrew calendar, depending if it's a leap year. When it's a leap year, Adar (which generally is in the late winter or early spring) is doubled into a "first Adar" (Adar1) and a "second Adar" (Adar2).
  3. There is a 19 year cycle of leap years. So the first two years of the cycle are regular years, the one after that's a leap year. Then another two are regular, then a leap year. Then it's regular, leap, regular, regular, leap, regular, regular, leap.
  4. Year 3763 was the first year of its 19 year cycle.
  5. Now you can calculate when's the New Moon before a given Rosh Hashana.

So how to calculate Rosh Hashana:

  1. If the New Moon is in the afternoon, Rosh Hashana is postponed to the next day.
  2. If Rosh Hashana's starting on a Sunday (Saturday night), Wednesday (Tuesday night), or Friday (Thursday night) - postpone it by a day.

If any of the above two conditions were fulfilled. Good. You just found Rosh Hashana. If not:

  1. If the New Moon is on a Tuesday after 3am+204 Chalakim and the coming year is not a leap year, Rosh Hashana is postponed to that upcoming Thursday instead.
  2. If the New Moon is on a Monday after 9am+589 Chalakim, and the previous year was a leap year, then Rosh Hashana is postponed to Tuesday.

Now you have all the Rosh Hashanas.

  1. In general, Months alternate between “Full” (30 days long) and “Empty” (29 days long) months. So Tishrei is full, Teves is empty, Shvat is full, Adar is empty, Nissan is full.
  2. When the year is a leap year, Adar 1 is full and Adar 2 is empty. (So a full Shvat is followed by a full Adar1).

Knowing this, you can calculate any other date of the year.

But wait! We're playing with the date when Rosh Hashana will start, so not every year will be the same length! How do we make up these days?

So there's a last little bit:

  1. Cheshvan and Kislev are variable length months – some years both are full, some years both are empty, and some years Cheshvan is full and Kislev is empty - depending on the day Rosh Hashana starts (and the day the next Rosh Hashana starts) and how many days are in the year.

pub fn day(&self) -> u8[src]

Get the Hebrew day of month.

pub fn month(&self) -> HebrewMonth[src]

Get the Hebrew month of year

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

Get the Hebrew year.

Trait Implementations

impl PartialOrd<HebrewDate> for HebrewDate[src]

#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0
[src]

This method tests less than (for self and other) and is used by the < operator. Read more

#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0
[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0
[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0
[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl Copy for HebrewDate[src]

impl PartialEq<HebrewDate> for HebrewDate[src]

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0
[src]

This method tests for !=.

impl Clone for HebrewDate[src]

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

Performs copy-assignment from source. Read more

impl Ord for HebrewDate[src]

fn max(self, other: Self) -> Self
1.21.0
[src]

Compares and returns the maximum of two values. Read more

fn min(self, other: Self) -> Self
1.21.0
[src]

Compares and returns the minimum of two values. Read more

impl Eq for HebrewDate[src]

impl Debug for HebrewDate[src]

Auto Trait Implementations

impl Send for HebrewDate

impl Sync for HebrewDate

Blanket Implementations

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

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

type Owned = T

impl<T> From for T[src]

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

impl<T, U> TryInto 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> Any for T where
    T: 'static + ?Sized
[src]