Struct HebrewDate

Source
pub struct HebrewDate { /* private fields */ }
Expand description

HebrewDate holds a specific Hebrew Date. It can be constructed individually or through HebrewYear.

Implementations§

Source§

impl HebrewDate

Source

pub fn from_ymd( year: u64, month: HebrewMonth, day: NonZeroI8, ) -> Result<HebrewDate, ConversionError>

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.
  • 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.
§Notes:

Day must be above zero. If it’s below zero, the function returns TooManyDaysInMonth. In a future release, day will be a NonZeroU8 so that it will be impossible to supply a negative number.

Source

pub fn day(&self) -> NonZeroI8

Get the Hebrew day of month.

Source

pub fn month(&self) -> HebrewMonth

Get the Hebrew month of year

Source

pub fn year(&self) -> u64

Get the Hebrew year.

Trait Implementations§

Source§

impl Clone for HebrewDate

Source§

fn clone(&self) -> HebrewDate

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for HebrewDate

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<HebrewDate> for DateTime<Utc>

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

use std::num::NonZeroI8;

use chrono::prelude::*;
use heca_lib::prelude::*;
use heca_lib::HebrewDate;

let gregorian_date: DateTime<Utc> = HebrewDate::from_ymd(5779,HebrewMonth::Tishrei,NonZeroI8::new(10).unwrap())?.into();
assert_eq!(gregorian_date ,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.
Source§

fn from(h: HebrewDate) -> Self

Converts to this type from the input type.
Source§

impl Ord for HebrewDate

Source§

fn cmp(&self, other: &HebrewDate) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for HebrewDate

Source§

fn eq(&self, other: &HebrewDate) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for HebrewDate

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for HebrewDate

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl TryFrom<DateTime<Utc>> for HebrewDate

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

§Arguments

  • date - The Gregorian date.

§Note:

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, most calendars will say that it’s on Monday the 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:

use std::num::NonZeroI8;
use std::convert::TryInto;

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

let hebrew_date: HebrewDate = Utc.ymd(2018,9,10).and_hms(17,59,59).try_into()?;
assert_eq!(hebrew_date,HebrewDate::from_ymd(5779,HebrewMonth::Tishrei,NonZeroI8::new(1).unwrap())?);

while

use std::num::NonZeroI8;
use std::convert::TryInto;

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


let hebrew_date: HebrewDate = Utc.ymd(2018,9,10).and_hms(18,0,0).try_into()?;
assert_eq!(hebrew_date, HebrewDate::from_ymd(5779,HebrewMonth::Tishrei,NonZeroI8::new(2).unwrap())?);

§Error Values:

  • YearTooSmall - This algorithm won’t work if the year is before year 4.
Source§

type Error = ConversionError

The type returned in the event of a conversion error.
Source§

fn try_from(original_day: DateTime<Utc>) -> Result<HebrewDate, ConversionError>

Performs the conversion.
Source§

impl Copy for HebrewDate

Source§

impl Eq for HebrewDate

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.