Skip to main content

BrightDate

Struct BrightDate 

Source
pub struct BrightDate {
    pub value: f64,
    pub precision: Precision,
    pub is_tai: bool,
}
Expand description

Immutable BrightDate value — decimal days since J2000.0 epoch.

This is the primary type for nearly all time operations. Wrap a raw f64 value to get the full BrightDate API including formatting, arithmetic, and conversion methods.

Fields§

§value: f64

Raw decimal-day value since J2000.0

§precision: Precision

Display precision (decimal places)

§is_tai: bool

Whether this value is on the TAI timescale

Implementations§

Source§

impl BrightDate

Source

pub fn from_value(value: f64) -> Self

Create from a raw f64 value (decimal days since J2000.0).

Source

pub fn from_value_with_options(value: f64, options: BrightDateOptions) -> Self

Create from a raw value with full options.

Source

pub fn now() -> Self

Current time as a BrightDate (UTC).

Source

pub fn from_date_time(dt: DateTime<Utc>) -> Self

Create from a chrono::DateTime<Utc>.

Source

pub fn from_unix_ms(ms: f64) -> Result<Self, BrightDateError>

Create from a Unix timestamp in milliseconds.

Source

pub fn from_unix_seconds(s: f64) -> Result<Self, BrightDateError>

Create from a Unix timestamp in seconds.

Source

pub fn from_julian_date(jd: f64) -> Self

Create from a Julian Date.

Source

pub fn from_modified_julian_date(mjd: f64) -> Self

Create from a Modified Julian Date.

Source

pub fn from_iso(s: &str) -> Result<Self, BrightDateError>

Create from an ISO 8601 string.

Source

pub fn from_gps_time(gps_week: u32, gps_seconds: f64) -> Self

Create from GPS week number and seconds within that week.

Source

pub fn epoch() -> Self

The J2000.0 epoch itself (value = 0.0).

Source

pub fn to_date_time(&self) -> DateTime<Utc>

Convert to a chrono::DateTime<Utc>.

Source

pub fn to_unix_ms(&self) -> f64

Convert to Unix milliseconds.

Source

pub fn to_unix_seconds(&self) -> f64

Convert to Unix seconds.

Source

pub fn to_julian_date(&self) -> f64

Convert to Julian Date.

Source

pub fn to_modified_julian_date(&self) -> f64

Convert to Modified Julian Date.

Source

pub fn to_iso(&self) -> String

Convert to ISO 8601 string.

Source

pub fn to_gps_time(&self) -> (u32, f64)

Convert to GPS time (gps_week, gps_seconds).

Source

pub fn to_tai(&self) -> Self

Mark this BrightDate as TAI-flagged. In v1.0 the underlying value is always TAI-coherent, so this only toggles the display flag.

Source

pub fn to_utc(&self) -> Self

Mark this BrightDate as UTC-flagged. In v1.0 the underlying value is always TAI-coherent, so this only toggles the display flag.

Source

pub fn tai_utc_offset_seconds(&self) -> i32

Current TAI − UTC offset in whole seconds at this instant.

Source

pub fn add_days(&self, days: f64) -> Self

Add days (decimal days) to this BrightDate.

Source

pub fn sub_days(&self, days: f64) -> Self

Subtract days (decimal days) from this BrightDate.

Source

pub fn add_millidays(&self, md: f64) -> Self

Add millidays.

Source

pub fn add_microdays(&self, ud: f64) -> Self

Add microdays.

Source

pub fn difference(&self, other: &Self) -> f64

Signed difference self − other in decimal days.

Source

pub fn absolute_difference(&self, other: &Self) -> f64

Absolute difference from other in decimal days.

Source

pub fn compare(&self, other: &Self) -> Ordering

Compare ordering to other.

Source

pub fn approx_eq(&self, other: &Self, tolerance: Option<f64>) -> bool

Test equality within tolerance decimal days (default: 1 microday).

Source

pub fn is_before(&self, other: &Self) -> bool

True if self < other.

Source

pub fn is_after(&self, other: &Self) -> bool

True if self > other.

Source

pub fn is_in_range(&self, start: &Self, end: &Self) -> bool

True if self falls in [start, end].

Source

pub fn lerp(&self, other: &Self, t: f64) -> Self

Linear interpolation between self and other at parameter t ∈ [0,1].

Source

pub fn midpoint(&self, other: &Self) -> Self

Midpoint between self and other.

Source

pub fn floor_to_day(&self) -> Self

Floor to the nearest whole day boundary.

Source

pub fn ceil_to_day(&self) -> Self

Ceiling to the nearest whole day boundary.

Source

pub fn round_to_milliday(&self) -> Self

Round to nearest milliday.

Source

pub fn round_to_microday(&self) -> Self

Round to nearest microday.

Source

pub fn format(&self) -> String

Format as decimal-day string with this instance’s precision, e.g. "9622.50417".

Source

pub fn decompose(&self) -> BrightDateComponents

Full decomposed struct.

Source

pub fn format_full(&self) -> FormattedBrightDate

Full formatted breakdown.

Source

pub fn to_log_string(&self) -> String

Compact log string, e.g. "[9622.50417]".

Source

pub fn to_prefixed_string(&self, prefix: Option<&str>) -> String

Prefixed string, e.g. "BD:9622.50417".

Source

pub fn format_duration_to(&self, other: &Self) -> String

Format duration from self to other.

Source

pub fn duration_to(&self, other: &Self) -> BrightDuration

Duration breakdown.

Source

pub fn format_range_to(&self, other: &Self) -> String

Range string for self..=other.

Trait Implementations§

Source§

impl Add<f64> for BrightDate

Source§

type Output = BrightDate

The resulting type after applying the + operator.
Source§

fn add(self, rhs: f64) -> Self

Performs the + operation. Read more
Source§

impl Clone for BrightDate

Source§

fn clone(&self) -> BrightDate

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BrightDate

Source§

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

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

impl<'de> Deserialize<'de> for BrightDate

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 BrightDate

Source§

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

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

impl PartialEq for BrightDate

Source§

fn eq(&self, other: &BrightDate) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 BrightDate

Source§

fn partial_cmp(&self, other: &BrightDate) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 BrightDate

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<f64> for BrightDate

Source§

type Output = BrightDate

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: f64) -> Self

Performs the - operation. Read more
Source§

impl Sub for BrightDate

Source§

type Output = f64

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: BrightDate) -> f64

Performs the - operation. Read more
Source§

impl Copy for BrightDate

Source§

impl StructuralPartialEq for BrightDate

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> 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>,