pub struct Instant {
pub raw: i64,
}Expand description
A module for handling time and date conversions. Time is stored natively as the number of microseconds since the Unix epoch (1970-01-01 00:00:00 UTC) with leap seconds accounted for.
The Instant struct provides methods for converting to and from Unix time, GPS time, Julian Date, Modified Julian Date, and Gregorian calendar date.
Why do we need another structure that handles time?
This structure is necessary as it is time scale aware, i.e. it can handle different time scales such as UTC, TAI, TT, UT1, GPS, etc. This is necessary for high-precision coordinate transforms and orbit propagation.
Fields§
§raw: i64The number of microseconds since Unix epoch (1970-01-01 00:00:00 UTC)
Implementations§
Source§impl Instant
impl Instant
Sourcepub const J2000: Self
pub const J2000: Self
J2000 epoch is 2000-01-01 12:00:00 TT TT (Terrestrial Time) is 32.184 seconds ahead of TAI
Sourcepub const UNIX_EPOCH: Self
pub const UNIX_EPOCH: Self
Unix epoch is 1970-01-01 00:00:00 UTC
pub const INVALID: Self
Sourcepub fn from_gps_week_and_second(week: i32, sow: f64) -> Self
pub fn from_gps_week_and_second(week: i32, sow: f64) -> Self
Sourcepub fn from_unixtime(unixtime: f64) -> Self
pub fn from_unixtime(unixtime: f64) -> Self
Sourcepub fn as_unixtime(&self) -> f64
pub fn as_unixtime(&self) -> f64
Sourcepub fn day_of_week(&self) -> Weekday
pub fn day_of_week(&self) -> Weekday
Return the day of the week 0 = Sunday, 1 = Monday, …, 6 = Saturday
See: https://en.wikipedia.org/wiki/Determination_of_the_day_of_the_week
Sourcepub fn as_mjd(&self) -> f64
👎Deprecated: Use as_mjd_utc() for explicit scale, or as_mjd_with_scale()
pub fn as_mjd(&self) -> f64
Use as_mjd_utc() for explicit scale, or as_mjd_with_scale()
As Modified Julian Date (UTC) Days since 1858-11-17 00:00:00 UTC where each day is 86,400 seconds (no leap seconds)
Sourcepub fn as_mjd_utc(&self) -> f64
pub fn as_mjd_utc(&self) -> f64
As Modified Julian Date (UTC) Days since 1858-11-17 00:00:00 UTC where each day is 86,400 seconds (no leap seconds)
Sourcepub fn from_mjd(mjd: f64) -> Self
👎Deprecated: Use from_mjd_utc() for explicit scale, or from_mjd_with_scale()
pub fn from_mjd(mjd: f64) -> Self
Use from_mjd_utc() for explicit scale, or from_mjd_with_scale()
Sourcepub fn from_mjd_utc(mjd: f64) -> Self
pub fn from_mjd_utc(mjd: f64) -> Self
Sourcepub fn from_jd(jd: f64) -> Self
👎Deprecated: Use from_jd_utc() for explicit scale, or from_jd_with_scale()
pub fn from_jd(jd: f64) -> Self
Use from_jd_utc() for explicit scale, or from_jd_with_scale()
Sourcepub fn from_jd_utc(jd: f64) -> Self
pub fn from_jd_utc(jd: f64) -> Self
Sourcepub fn from_jd_with_scale(jd: f64, scale: TimeScale) -> Self
pub fn from_jd_with_scale(jd: f64, scale: TimeScale) -> Self
Sourcepub fn from_mjd_with_scale(mjd: f64, scale: TimeScale) -> Self
pub fn from_mjd_with_scale(mjd: f64, scale: TimeScale) -> Self
Sourcepub fn as_jd(&self) -> f64
👎Deprecated: Use as_jd_utc() for explicit scale, or as_jd_with_scale()
pub fn as_jd(&self) -> f64
Use as_jd_utc() for explicit scale, or as_jd_with_scale()
As Julian Date (UTC) Days since 4713 BC January 1, 12:00 UTC where each day is 86,400 seconds (no leap seconds)
Sourcepub fn as_jd_utc(&self) -> f64
pub fn as_jd_utc(&self) -> f64
As Julian Date (UTC) Days since 4713 BC January 1, 12:00 UTC where each day is 86,400 seconds (no leap seconds)
Sourcepub fn as_jd_with_scale(&self, scale: TimeScale) -> f64
pub fn as_jd_with_scale(&self, scale: TimeScale) -> f64
Sourcepub fn add_utc_days(&self, days: f64) -> Self
pub fn add_utc_days(&self, days: f64) -> Self
Add given floating-point number of days to Instant instance, and return new instance representing new time.
Days are defined in this case to have exactly 86400.0 seconds In other words, this will ignore leap seconds and the integer part of the floating point will increment the number of days and the decimal part will increment the fractions of a day.
So, for example, adding 1.0 to a day with a leap second will increment by a full day
§Arguments
days- The number of days to add
§Returns
A new Instant object representing the new time
Sourcepub fn as_mjd_with_scale(&self, scale: TimeScale) -> f64
pub fn as_mjd_with_scale(&self, scale: TimeScale) -> f64
Sourcepub fn day_of_year(&self) -> u32
pub fn day_of_year(&self) -> u32
Return the day of the year (1-based, Gregorian); leap-year aware.
§Returns
The day of the year (1-based, Gregorian); leap-year aware.
§Notes:
- Gregorian Jan 1 = 1
§Example
// Examples checked against google query
let thedate = satkit::Instant::from_date(2023, 1, 1).unwrap();
assert_eq!(thedate.day_of_year(), 1);
let thedate = satkit::Instant::from_date(2025, 8, 16).unwrap();
assert_eq!(thedate.day_of_year(), 228);Sourcepub fn utc(
year: i32,
month: i32,
day: i32,
hour: i32,
minute: i32,
second: f64,
) -> Result<Self>
pub fn utc( year: i32, month: i32, day: i32, hour: i32, minute: i32, second: f64, ) -> Result<Self>
Convenience alias for from_datetime
Construct an instant from a given Gregorian UTC date and time
§Arguments
year- The yearmonth- The month (1-12)day- The day (1-31)hour- The hour (0-23)minute- The minute (0-59)second- The second (0.0-60.0)
§Returns
A new Instant object representing the given date and time, or error if invalid
Sourcepub fn from_datetime(
year: i32,
month: i32,
day: i32,
hour: i32,
minute: i32,
second: f64,
) -> Result<Self>
pub fn from_datetime( year: i32, month: i32, day: i32, hour: i32, minute: i32, second: f64, ) -> Result<Self>
Construct an instant from a given Gregorian UTC date and time
§Arguments
year- The yearmonth- The monthday- The dayhour- The hourminute- The minutesecond- The second
§Returns
A new Instant object representing the given date and time, or error if invalid or error if the month, day, hour, minute, or second are out of bounds
Source§impl Instant
impl Instant
Sourcepub fn from_string(s: &str) -> Result<Self>
pub fn from_string(s: &str) -> Result<Self>
Sourcepub fn strptime(s: &str, format: &str) -> Result<Self>
pub fn strptime(s: &str, format: &str) -> Result<Self>
Parse a string into an Instant object
§Notes:
- The format string is a subset of the Python datetime module
§Arguments:
- s (str): The string to parse
- format (str): The format string
§Format Codes:
- %Y - Year with century as a decimal number
- %m - Month as a zero-padded decimal number [01, 12]
- %B - Full month name (January, February, etc.)
- %b - Abbreviated month name (Jan, Feb, etc.)
- %d - Day of the month as a zero-padded decimal number [01, 31]
- %H - Hour (24-hour clock) as a zero-padded decimal number
- %M - Minute as a zero-padded decimal number
- %S - Second as a zero-padded decimal number
- %f - Microsecond as a decimal number, allowing for trailing zeros
- %z - UTC offset in the form +HHMM or -HHMM or ‘Z’ for UTC
§Returns:
Instant: The instant object
Sourcepub fn from_rfc3339(rfc3339: &str) -> Result<Self, InstantError>
pub fn from_rfc3339(rfc3339: &str) -> Result<Self, InstantError>
Sourcepub fn as_rfc3339(&self) -> String
pub fn as_rfc3339(&self) -> String
Sourcepub fn as_iso8601(&self) -> String
pub fn as_iso8601(&self) -> String
Sourcepub fn strftime(&self, format: &str) -> Result<String, InstantError>
pub fn strftime(&self, format: &str) -> Result<String, InstantError>
Format the Instant object as a string
§Notes:
- The format string is a subset of the Python datetime module
§Arguments:
format (str): The format string
§Format Codes:
- %Y - Year with century as a decimal number
- %m - Month as a zero-padded decimal number [01, 12]
- %B - Full month name (January, February, etc.)
- %b - Abbreviated month name (Jan, Feb, etc.)
- %d - Day of the month as a zero-padded decimal number [01, 31]
- %H - Hour (24-hour clock) as a zero-padded decimal number
- %M - Minute as a zero-padded decimal number
- %S - Second as a zero-padded decimal number
- %f - Microsecond as a decimal number
- %A - Full weekday name (Sunday, Monday, etc.)
- %w - Weekday as a decimal number [0(Sunday), 6(Saturday)]
§Returns:
str: The formatted string
Trait Implementations§
Source§impl AddAssign<Duration> for Instant
impl AddAssign<Duration> for Instant
Source§fn add_assign(&mut self, other: Duration)
fn add_assign(&mut self, other: Duration)
+= operation. Read moreSource§impl<'de> Deserialize<'de> for Instant
impl<'de> Deserialize<'de> for Instant
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Ord for Instant
impl Ord for Instant
Source§impl PartialEq<Instant> for SpaceWeatherRecord
impl PartialEq<Instant> for SpaceWeatherRecord
Source§impl PartialOrd<Instant> for SpaceWeatherRecord
impl PartialOrd<Instant> for SpaceWeatherRecord
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, other: Duration)
fn sub_assign(&mut self, other: Duration)
-= operation. Read moreSource§impl TimeLike for Instant
impl TimeLike for Instant
Source§fn as_mjd_with_scale(&self, scale: TimeScale) -> f64
fn as_mjd_with_scale(&self, scale: TimeScale) -> f64
Source§fn as_jd_with_scale(&self, scale: TimeScale) -> f64
fn as_jd_with_scale(&self, scale: TimeScale) -> f64
Source§fn as_instant(&self) -> Instant
fn as_instant(&self) -> Instant
Instant in UTC. Read moreimpl Copy for Instant
impl Eq for Instant
Auto Trait Implementations§
impl Freeze for Instant
impl RefUnwindSafe for Instant
impl Send for Instant
impl Sync for Instant
impl Unpin for Instant
impl UnsafeUnpin for Instant
impl UnwindSafe for Instant
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more