Skip to main content

Instant

Struct Instant 

Source
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: i64

The number of microseconds since Unix epoch (1970-01-01 00:00:00 UTC)

Implementations§

Source§

impl Instant

Source

pub const J2000: Self

J2000 epoch is 2000-01-01 12:00:00 TT TT (Terrestrial Time) is 32.184 seconds ahead of TAI

Source

pub const UNIX_EPOCH: Self

Unix epoch is 1970-01-01 00:00:00 UTC

Source

pub const GPS_EPOCH: Self

GPS epoch is 1980-01-06 00:00:00 UTC

Source

pub const INVALID: Self

Source

pub const MJD_EPOCH: Self

Modified Julian day epoch is 1858-11-17 00:00:00 UTC

Source

pub const fn new(raw: i64) -> Self

Construct a new Instant from raw microseconds

§Arguments
  • raw - The number of microseconds since unixtime epoch
§Returns

A new Instant object

§Example
use satkit::Instant;
let now = Instant::new(1234567890);
Source

pub fn from_gps_week_and_second(week: i32, sow: f64) -> Self

Construct a new Instant from GPS week and second of week

§Arguments
  • week - The GPS week number
  • sow - The second of week
§Returns

A new Instant object

Source

pub fn from_unixtime(unixtime: f64) -> Self

Construct a new Instant from Unix time

§Arguments
  • unixtime - The Unix time in seconds
§Returns

A new Instant object representing the input Unix time

§Note:

Unixtime is the number of non-leap seconds since Jan 1 1970 00:00:00 UTC (Leap seconds are ignored!!)

Source

pub fn as_unixtime(&self) -> f64

Convert Instant to Unix time

§Returns

The Unix time in seconds (since 1970-01-01 00:00:00 UTC)

§Note

Unixtime is the number of non-leap seconds since 1970-01-01 00:00:00 UTC.

Source

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

Source

pub fn as_mjd(&self) -> f64

👎Deprecated:

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)

Source

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)

Source

pub fn from_mjd(mjd: f64) -> Self

👎Deprecated:

Use from_mjd_utc() for explicit scale, or from_mjd_with_scale()

Create Instant from Modified Julian Date (UTC)

§Arguments
  • mjd - Modified Julian Date (UTC)
§Returns

A new Instant object representing the given MJD

Source

pub fn from_mjd_utc(mjd: f64) -> Self

Create Instant from Modified Julian Date (UTC)

§Arguments
  • mjd - Modified Julian Date (UTC)
§Returns

A new Instant object representing the given MJD

Source

pub fn from_jd(jd: f64) -> Self

👎Deprecated:

Use from_jd_utc() for explicit scale, or from_jd_with_scale()

Create Instant from Julian Date (UTC)

§Arguments
  • jd - Julian Date (UTC)
§Returns

A new Instant object representing the given JD

Source

pub fn from_jd_utc(jd: f64) -> Self

Create Instant from Julian Date (UTC)

§Arguments
  • jd - Julian Date (UTC)
§Returns

A new Instant object representing the given JD

Source

pub fn from_jd_with_scale(jd: f64, scale: TimeScale) -> Self

Create Instant from Julian Date with given time scale (UTC, TAI, TT, UT1, GPS) Days since 4713 BC January 1, 12:00 UTC

§Arguments
  • jd - Julian Date
  • scale - The time scale to use
§Returns

A new Instant object representing the given JD at given time scale

Source

pub fn from_mjd_with_scale(mjd: f64, scale: TimeScale) -> Self

Construct an instant from a given Modified Julian Date and time scale

§Arguments
  • mjd - The Modified Julian Date
  • scale - The time scale to use
§Returns

A new Instant object representing the given MJD at given time scale

Source

pub fn as_jd(&self) -> f64

👎Deprecated:

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)

Source

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)

Source

pub fn as_jd_with_scale(&self, scale: TimeScale) -> f64

As Julian Date with given time scale Days since 4713 BC January 1, 12:00 UTC

§Arguments
  • scale - The time scale to use
§Returns

The Julian Date in the given time scale

Source

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

Source

pub fn as_mjd_with_scale(&self, scale: TimeScale) -> f64

As Modified Julian Date with given time scale Days since 1858-11-17 00:00:00 UTC

§Arguments
  • scale - The time scale to use
§Returns

The Modified Julian Date in the given time scale

Source

pub fn as_datetime(&self) -> (i32, i32, i32, i32, i32, f64)

Return the Gregorian date and time

§Returns

(year, month, day, hour, minute, second), UTC

Source

pub fn from_date(year: i32, month: i32, day: i32) -> Result<Self>

Construct an instant from a given UTC date

§Arguments
  • year - The year
  • month - The month
  • day - The day
§Returns

A new Instant object representing the given date

Source

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);
Source

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 year
  • month - 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

Source

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 year
  • month - The month
  • day - The day
  • hour - The hour
  • minute - The minute
  • second - 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

pub fn now() -> Self

Current time

§Returns

The current time as an Instant object

§Example
use satkit::Instant;
let now = Instant::now();
Source§

impl Instant

Source

pub fn from_string(s: &str) -> Result<Self>

Parse a string into an Instant object

Attempts to guess the string format. Use sparingly and with caution. This is probably not what you want.

§Arguments:

s (str): The string to parse

§Returns:

Instant: The instant object

§Raises:

SCErr: If the string cannot be parsed

Source

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

Source

pub fn from_rfc3339(rfc3339: &str) -> Result<Self, InstantError>

Parse a string in RFC3339 format

§Arguments:

rfc3339 (str): The string in RFC3339 format

§Notes:
  • Only allows a subset of the RFC3339 format: “YYYY-MM-DDTHH:MM:SS.sssZ”
§Returns:

Instant: The instant object

Source

pub fn as_rfc3339(&self) -> String

Format the Instant object as a string in RFC3339 format

§Returns:

str: The formatted string in RFC3339 format: “YYYY-MM-DDTHH:MM:SS.sssZ”

§Notes:
  • This is the same as ISO8601 format
Source

pub fn as_iso8601(&self) -> String

Format the Instant object as a string in ISO8601 format

§Returns:

str: The formatted string in ISO8601 format: “YYYY-MM-DDTHH:MM:SS.sssZ”

§Notes:
  • This is the same as RFC3339 format
Source

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 Add<Duration> for &Instant

Source§

type Output = Instant

The resulting type after applying the + operator.
Source§

fn add(self, other: Duration) -> Instant

Performs the + operation. Read more
Source§

impl Add<Duration> for Instant

Source§

type Output = Instant

The resulting type after applying the + operator.
Source§

fn add(self, other: Duration) -> Self

Performs the + operation. Read more
Source§

impl AddAssign<Duration> for Instant

Source§

fn add_assign(&mut self, other: Duration)

Performs the += operation. Read more
Source§

impl Clone for Instant

Source§

fn clone(&self) -> Instant

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 Instant

Source§

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

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

impl<'de> Deserialize<'de> for Instant

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Instant

Source§

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

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

impl Ord for Instant

Source§

fn cmp(&self, other: &Self) -> 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<Instant> for SpaceWeatherRecord

Source§

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

Source§

fn eq(&self, other: &Self) -> 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<Instant> for SpaceWeatherRecord

Source§

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

Source§

fn partial_cmp(&self, other: &Self) -> 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 Serialize for Instant

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Sub<Duration> for &Instant

Source§

type Output = Instant

The resulting type after applying the - operator.
Source§

fn sub(self, other: Duration) -> Instant

Performs the - operation. Read more
Source§

impl Sub<Duration> for Instant

Source§

type Output = Instant

The resulting type after applying the - operator.
Source§

fn sub(self, other: Duration) -> Self

Performs the - operation. Read more
Source§

impl Sub<Instant> for &Instant

Source§

type Output = Duration

The resulting type after applying the - operator.
Source§

fn sub(self, other: Instant) -> Duration

Performs the - operation. Read more
Source§

impl Sub for Instant

Source§

type Output = Duration

The resulting type after applying the - operator.
Source§

fn sub(self, other: Self) -> Duration

Performs the - operation. Read more
Source§

impl SubAssign<Duration> for Instant

Source§

fn sub_assign(&mut self, other: Duration)

Performs the -= operation. Read more
Source§

impl TimeLike for Instant

Source§

fn as_mjd_with_scale(&self, scale: TimeScale) -> f64

Modified Julian Date with the provided time scale.
Source§

fn as_jd_with_scale(&self, scale: TimeScale) -> f64

Julian Date with the provided time scale.
Source§

fn as_instant(&self) -> Instant

Convert to a satkit Instant in UTC. Read more
Source§

impl Copy for Instant

Source§

impl Eq for Instant

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,