pub struct JulianDay(pub i64);Expand description
Store a proleptic gregorian date as JulianDay
The Julian Day Number or Julian Day is the number of days since noon UTC on November 24 of the
year -4713 in the Gregorian Calendar. The year 0 equals 1BC. The JD number is a possibly
negative integer representing the number of whole days since the reference instant to noon of
that day. This JulianDay implementation does not have a fraction and stores the day as if no
time was specified which is equivalent of a time being always noon.
§Examples
use fundu_gnu::JulianDay;
assert_eq!(JulianDay(0).to_gregorian(), Some((-4713, 11, 24)));
assert_eq!(JulianDay(-365).to_gregorian(), Some((-4714, 11, 24)));
assert_eq!(JulianDay(1_721_060).to_gregorian(), Some((0, 1, 1)));
assert_eq!(JulianDay(2_440_588).to_gregorian(), Some((1970, 1, 1)));Tuple Fields§
§0: i64Implementations§
Source§impl JulianDay
impl JulianDay
Sourcepub const fn from_gregorian(year: i64, month: u8, day: u8) -> Self
pub const fn from_gregorian(year: i64, month: u8, day: u8) -> Self
Calculate the JulianDay from a proleptic gregorian date
For a non-panicking version see JulianDay::try_from_gregorian.
§Panics
Panics if the input arguments are invalid. Valid ranges are:
1 <= month <= 121 <= day <= 31
or an overflow occurred. Use the safer alternative JulianDay::try_from_gregorian if very
high values for years are expected.
§Examples
use fundu_gnu::JulianDay;
assert_eq!(JulianDay::from_gregorian(-4713, 11, 24), JulianDay(0));
assert_eq!(JulianDay::from_gregorian(-4714, 11, 24), JulianDay(-365));
assert_eq!(JulianDay::from_gregorian(0, 1, 1), JulianDay(1_721_060));
assert_eq!(JulianDay::from_gregorian(1970, 1, 1), JulianDay(2440588));Sourcepub const fn try_from_gregorian(year: i64, month: u8, day: u8) -> Option<Self>
pub const fn try_from_gregorian(year: i64, month: u8, day: u8) -> Option<Self>
Calculate the JulianDay from a proleptic gregorian date
Returns None if an overflow occurred most likely to a year greater than approximately
25_200_470_046_046_596 or smaller than approximately -25_200_470_046_046_596
This method is based on the work of Peter Baum and his publication of Date Algorithms.
§Panics
Panics if the input arguments are invalid. Valid ranges are:
1 <= month <= 121 <= day <= 31
Note it is not an error to specify day = 31 for example for the month 4 (April). In such a
case the month is assumed to be the next month (here May) and day = 1.
§Examples
use fundu_gnu::JulianDay;
assert_eq!(
JulianDay::try_from_gregorian(-4713, 11, 24),
Some(JulianDay(0))
);
assert_eq!(
JulianDay::try_from_gregorian(-4714, 11, 24),
Some(JulianDay(-365))
);
assert_eq!(
JulianDay::try_from_gregorian(0, 1, 1),
Some(JulianDay(1_721_060))
);
assert_eq!(
JulianDay::try_from_gregorian(1970, 1, 1),
Some(JulianDay(2440588))
);Sourcepub fn to_gregorian(self) -> Option<(i64, u8, u8)>
pub fn to_gregorian(self) -> Option<(i64, u8, u8)>
Calculate the proleptic gregorian date from this JulianDay
The method returns None if an overflow occurred.
This method is based on the work of Peter Baum and his publication of Date Algorithms.
§Examples
use fundu_gnu::JulianDay;
assert_eq!(JulianDay(-365).to_gregorian(), Some((-4714, 11, 24)));
assert_eq!(JulianDay(0).to_gregorian(), Some((-4713, 11, 24)));
assert_eq!(JulianDay(1721060).to_gregorian(), Some((0, 1, 1)));
assert_eq!(JulianDay(2440588).to_gregorian(), Some((1970, 1, 1)));Sourcepub const fn checked_add_days(self, days: i64) -> Option<Self>
pub const fn checked_add_days(self, days: i64) -> Option<Self>
Checked days addition. Computes self.0 + days, returning None if an overflow occurred.
§Examples
use fundu_gnu::JulianDay;
assert_eq!(
JulianDay(0).checked_add_days(10_000),
Some(JulianDay(10_000))
);
assert_eq!(JulianDay(0).checked_add_days(-1), Some(JulianDay(-1)));Sourcepub const fn checked_sub_days(self, days: i64) -> Option<Self>
pub const fn checked_sub_days(self, days: i64) -> Option<Self>
Checked days subtraction. Computes self.0 - days, returning None if an overflow occurred.
§Examples
use fundu_gnu::JulianDay;
assert_eq!(
JulianDay(1_700_000).checked_sub_days(1),
Some(JulianDay(1_699_999))
);
assert_eq!(JulianDay(0).checked_sub_days(366), Some(JulianDay(-366)));Sourcepub const fn checked_add(self, rhs: Self) -> Option<Self>
pub const fn checked_add(self, rhs: Self) -> Option<Self>
Checked addition. Computes self + rhs, returning None if an overflow occurred.
§Examples
use fundu_gnu::JulianDay;
assert_eq!(
JulianDay(0).checked_add(JulianDay(10_000)),
Some(JulianDay(10_000))
);
assert_eq!(JulianDay(0).checked_add(JulianDay(-1)), Some(JulianDay(-1)));Sourcepub const fn checked_sub(self, rhs: Self) -> Option<Self>
pub const fn checked_sub(self, rhs: Self) -> Option<Self>
Checked subtraction. Computes self - rhs, returning None if an overflow occurred.
§Examples
use fundu_gnu::JulianDay;
assert_eq!(
JulianDay(1_700_000).checked_sub(JulianDay(1)),
Some(JulianDay(1_699_999))
);
assert_eq!(
JulianDay(0).checked_sub(JulianDay(366)),
Some(JulianDay(-366))
);