pub struct Instant(/* private fields */);Expand description
An Instant is a precise moment in time.
Internally this is stored as a Duration (which is 128 bits in size) offset from an opaque internally chosen epoch.
This represents the same thing that a DateTime does, but has advantages:
- It is easier to work with Durations by avoiding the complexity of the
Calendar - Spans a much larger time span, able to handle times from about 20 times as old as the age of the/ universe backwards, and the same distance forwards
- Provides attosecond (10^-18) precision.
Implementations§
Source§impl Instant
impl Instant
Sourcepub fn now() -> Result<Self, Error>
pub fn now() -> Result<Self, Error>
The current instant
§Errors
If the system time is greater than i64::MAX seconds, we will
get an Error::RangeError.
Sourcepub fn from_julian_day_f64(jd: f64) -> Self
pub fn from_julian_day_f64(jd: f64) -> Self
Create from a Julian Day (low precision)
This is not as precise as from_julian_day_parts(), and much less precise than
from_julian_day_precise()
Sourcepub fn from_julian_day_parts(day: i64, day_fraction: f64) -> Self
pub fn from_julian_day_parts(day: i64, day_fraction: f64) -> Self
Create from a Julian Day (medium precision)
This is more precise than from_julian_day_f64() but not as precise as
from_julian_day_precise()
Sourcepub fn from_julian_day_precise(
day: i64,
seconds: u32,
attoseconds: i64,
) -> Result<Self, Error>
pub fn from_julian_day_precise( day: i64, seconds: u32, attoseconds: i64, ) -> Result<Self, Error>
Create from a Julian Day (maximum precision)
This is more precise than from_julian_day_f64() but not as precise as
from_julian_day_precise()
§Errors
This will throw an Error::RangeError if the seconds are out of
bounds (0 <= seconds < 86_400) or the attoseconds are out of bounds
(0 <= attoseconds < ATTOS_PER_SEC_U64)
Sourcepub fn as_julian_day_f64(&self) -> f64
pub fn as_julian_day_f64(&self) -> f64
As Julian day (low precision)
Sourcepub fn as_julian_day_parts(&self) -> (i64, f64)
pub fn as_julian_day_parts(&self) -> (i64, f64)
As Julian day (medium precision)
This returns a day number and a day fraction.
Sourcepub fn as_julian_day_precise(&self) -> (i64, i64, i64)
pub fn as_julian_day_precise(&self) -> (i64, i64, i64)
As Julian day (high precision)
This returns a day number, a second number, and an attoseconds number
Sourcepub fn as_julian_day_formatted(&self) -> String
pub fn as_julian_day_formatted(&self) -> String
As julian day (formatted as a string)
Sourcepub fn as_ntp_date(&self) -> (i64, i64)
pub fn as_ntp_date(&self) -> (i64, i64)
As an NTP date, which is seconds and attoseconds.
This value is not returned as a Duration because NTP dates are incorrect durations from the NTP epoch (in that they don’t include leap seconds).
Sourcepub fn from_ntp_date(ntp_secs: i64, ntp_attos: i64) -> Self
pub fn from_ntp_date(ntp_secs: i64, ntp_attos: i64) -> Self
From an NTP date
Trait Implementations§
Source§impl AddAssign<Duration> for Instant
impl AddAssign<Duration> for Instant
Source§fn add_assign(&mut self, rhs: Duration)
fn add_assign(&mut self, rhs: Duration)
+= operation. Read moreSource§impl Ord for Instant
impl Ord for Instant
Source§impl PartialOrd for Instant
impl PartialOrd for Instant
Source§impl SubAssign<Duration> for Instant
impl SubAssign<Duration> for Instant
Source§fn sub_assign(&mut self, rhs: Duration)
fn sub_assign(&mut self, rhs: Duration)
-= operation. Read more