JulianDate

Struct JulianDate 

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

Representation of a proleptic Julian date. Only represents logic down to single-day accuracy: i.e., leap days are included, but leap seconds are not. This is useful in keeping this calendar applicable to all different time scales. Can represent years from -2^31 up to 2^31 - 1.

Implementations§

Source§

impl JulianDate

Source

pub const fn new( year: i32, month: Month, day: u8, ) -> Result<Self, InvalidJulianDate>

Creates a new Julian date, given its year, month, and day. If the date is not a valid proleptic Julian date, returns a JulianDateDoesNotExist to indicate that the requested date does not exist in the proleptic Julian calendar.

This function will never panic.

Source

pub const fn from_date(date: Date) -> Self

Constructs a Julian date from a given Date instance. Useful primarily when an existing Date must be printed in human-readable format.

Uses Howard Hinnant’s julian_from_days algorithm.

Source

pub const fn into_date(&self) -> Date

Constructs a Date from a given Julian date. Uses Howard Hinnant’s days_from_julian algorithm.

Source

pub const fn from_ordinal_date( year: i32, day_of_year: u16, ) -> Result<Self, InvalidDayOfYear>

Creates a new date given only the year and the day-of-year. Implementation is based on an algorithm found by A. Pouplier and reported by Jean Meeus in Astronomical Algorithms.

This function will never panic.

Source

pub const fn year(&self) -> i32

Returns the year stored inside this proleptic Julian date. Astronomical year numbering is used (as also done in NAIF SPICE): the year 1 BCE is represented as 0, 2 BCE as -1, etc. Hence, around the year 0, the numbering is …, -2 (3 BCE), -1 (2 BCE), 0 (1 BCE), 1 (1 CE), 2 (2 CE), et cetera. In this manner, the year numbering proceeds smoothly through 0.

Source

pub const fn month(&self) -> Month

Returns the month stored inside this proleptic Julian date.

Source

pub const fn day(&self) -> u8

Returns the day-of-month stored inside this proleptic Julian date.

Source§

impl JulianDate

Source

pub fn parse_partial( string: &str, ) -> Result<(Self, &str), JulianDateParsingError>

Parses a JulianDate based on some string. Accepts only the extended complete calendar date format specified in ISO 8601 (see section 5.2.2.1), though in addition any number of digits is accepted for the years term - to extend applicability of the format to a larger time range.

On success, returns the resulting JulianDate and any remaining input that was not yet parsed. On failure, returns a reason indicating why.

Trait Implementations§

Source§

impl Clone for JulianDate

Source§

fn clone(&self) -> JulianDate

Returns a duplicate 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 JulianDate

Source§

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

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

impl From<Date> for JulianDate

Source§

fn from(value: Date) -> Self

Converts to this type from the input type.
Source§

impl From<JulianDate> for Date

Source§

fn from(value: JulianDate) -> Self

Converts to this type from the input type.
Source§

impl FromStr for JulianDate

Source§

fn from_str(string: &str) -> Result<Self, Self::Err>

Parses a JulianDate based on some string. Accepts only the extended complete calendar date format specified in ISO 8601 (see section 5.2.2.1), though in addition any number of digits is accepted for each term.

Source§

type Err = JulianDateParsingError

The associated error which can be returned from parsing.
Source§

impl Ord for JulianDate

Source§

fn cmp(&self, other: &JulianDate) -> 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 JulianDate

Source§

fn eq(&self, other: &JulianDate) -> 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 JulianDate

Source§

fn partial_cmp(&self, other: &JulianDate) -> 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 Copy for JulianDate

Source§

impl Eq for JulianDate

Source§

impl StructuralPartialEq for JulianDate

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.