[−][src]Struct heca_lib::HebrewDate
HebrewDate holds a specific Hebrew Date. It can be constructed individually or through HebrewYear.
Implementations
impl HebrewDate
[src]
pub fn from_ymd(
year: u64,
month: HebrewMonth,
day: NonZeroI8
) -> Result<HebrewDate, ConversionError>
[src]
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.
pub fn day(&self) -> NonZeroI8
[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 Clone for HebrewDate
[src]
fn clone(&self) -> HebrewDate
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Copy for HebrewDate
[src]
impl Debug for HebrewDate
[src]
impl Eq for HebrewDate
[src]
impl From<HebrewDate> for 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
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:
- There are exactly 1080 Chalakim (parts) in an hour.
- 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:
- All months are either 29 or 30 days long.
- 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).
- 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.
- Year 3763 was the first year of its 19 year cycle.
- Now you can calculate when's the New Moon before a given Rosh Hashana.
So how to calculate Rosh Hashana:
- If the New Moon is in the afternoon, Rosh Hashana is postponed to the next day.
- 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:
- 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.
- 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.
- 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.
- 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:
- 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.
fn from(h: HebrewDate) -> Self
[src]
impl Ord for HebrewDate
[src]
fn cmp(&self, other: &HebrewDate) -> Ordering
[src]
#[must_use]fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn clamp(self, min: Self, max: Self) -> Self
[src]
impl PartialEq<HebrewDate> for HebrewDate
[src]
impl PartialOrd<HebrewDate> for HebrewDate
[src]
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
[src]
#[must_use]fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl Serialize for HebrewDate
[src]
impl TryFrom<DateTime<Utc>> for HebrewDate
[src]
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.
type Error = ConversionError
The type returned in the event of a conversion error.
fn try_from(original_day: DateTime<Utc>) -> Result<HebrewDate, ConversionError>
[src]
Auto Trait Implementations
impl RefUnwindSafe for HebrewDate
impl Send for HebrewDate
impl Sync for HebrewDate
impl Unpin for HebrewDate
impl UnwindSafe for HebrewDate
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,