[−][src]Struct heca_lib::convert::HebrewDate
HebrewDate is a struct containing a Hebrew date. There are two ways to generate it: Either HebrewDate::from_ymd()
or HebrewDate::from_gregorian()
.
Methods
impl HebrewDate
[src]
pub fn from_ymd(
year: u64,
month: HebrewMonth,
day: u8
) -> Result<HebrewDate, ConversionError>
[src]
year: u64,
month: HebrewMonth,
day: u8
) -> 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.
- 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]
date: DateTime<Utc>
) -> Result<HebrewDate, ConversionError>
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::{HebrewDate,HebrewMonth}; 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::{HebrewDate,HebrewMonth}; 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 Grgorian 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::{HebrewDate,HebrewMonth}; assert_eq!(HebrewDate::from_ymd(5779,HebrewMonth::Tishrei,10).unwrap().to_gregorian(),Utc.ymd(2018, 9,18).and_hms(18,00,00));
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 PartialEq<HebrewDate> for HebrewDate
[src]
fn eq(&self, other: &HebrewDate) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl Copy for HebrewDate
[src]
impl Clone for HebrewDate
[src]
fn clone(&self) -> HebrewDate
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Debug for HebrewDate
[src]
impl Display 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]
U: From<T>,
impl<T> From for T
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = !
try_from
)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> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,