pub struct Interval<T: TimeInstant> {
pub start: T,
pub end: T,
}Expand description
Represents an interval between two instants.
An Interval is defined by a start and end time instant of type T,
where T implements the TimeInstant trait. This allows for periods
defined in different time systems (Julian Date, Modified Julian Date, UTC, etc.).
§Examples
use tempoch::{Interval, ModifiedJulianDate};
let start = ModifiedJulianDate::new(59000.0);
let end = ModifiedJulianDate::new(59001.0);
let period = Interval::new(start, end);
// Duration in days
let duration = period.duration();Fields§
§start: T§end: TImplementations§
Source§impl<T: TimeInstant> Interval<T>
impl<T: TimeInstant> Interval<T>
Sourcepub fn duration(&self) -> T::Duration
pub fn duration(&self) -> T::Duration
Returns the duration of the period as the difference between end and start.
§Examples
use tempoch::{Interval, JulianDate};
use qtty::Days;
let start = JulianDate::new(2451545.0);
let end = JulianDate::new(2451546.5);
let period = Interval::new(start, end);
let duration = period.duration();
assert_eq!(duration, Days::new(1.5));Sourcepub fn intersection(&self, other: &Self) -> Option<Self>
pub fn intersection(&self, other: &Self) -> Option<Self>
Returns the overlapping sub-period between self and other.
Periods are treated as half-open ranges [start, end): if one period
ends exactly when the other starts, the intersection is empty and None
is returned.
Source§impl<S: TimeScale> Interval<Time<S>>
impl<S: TimeScale> Interval<Time<S>>
Sourcepub fn to<Target>(&self) -> Interval<<Target as PeriodTimeTarget<S>>::Instant>where
Target: PeriodTimeTarget<S>,
pub fn to<Target>(&self) -> Interval<<Target as PeriodTimeTarget<S>>::Instant>where
Target: PeriodTimeTarget<S>,
Convert this period to another time scale.
Each endpoint is converted preserving the represented absolute interval.
Supported targets:
- Any time-scale marker (
JD,MJD,UT, …) chrono::DateTime<Utc>
§Examples
use chrono::{DateTime, Utc};
use tempoch::{Interval, JD, MJD, Period, Time};
let period_jd = Period::new(Time::<JD>::new(2451545.0), Time::<JD>::new(2451546.0));
let period_mjd = period_jd.to::<MJD>();
let _period_utc: Interval<DateTime<Utc>> = period_jd.to::<DateTime<Utc>>();
assert!((period_mjd.start.value() - 51544.5).abs() < 1e-12);
assert!((period_mjd.end.value() - 51545.5).abs() < 1e-12);Source§impl<T: TimeInstant<Duration = Days>> Interval<T>
impl<T: TimeInstant<Duration = Days>> Interval<T>
Sourcepub fn duration_days(&self) -> Days
pub fn duration_days(&self) -> Days
Returns the duration of the period in days as a floating-point value.
This method is available for time instants with Days as their duration type
(e.g., JulianDate and ModifiedJulianDate).
§Examples
use tempoch::{Interval, ModifiedJulianDate};
use qtty::Days;
let start = ModifiedJulianDate::new(59000.0);
let end = ModifiedJulianDate::new(59001.5);
let period = Interval::new(start, end);
assert_eq!(period.duration_days(), Days::new(1.5));Source§impl Interval<DateTime<Utc>>
impl Interval<DateTime<Utc>>
Sourcepub fn to<Target>(&self) -> Interval<<Target as PeriodUtcTarget>::Instant>where
Target: PeriodUtcTarget,
pub fn to<Target>(&self) -> Interval<<Target as PeriodUtcTarget>::Instant>where
Target: PeriodUtcTarget,
Convert this UTC interval to another target.
Supported targets:
- Any time-scale marker (
JD,MJD,UT, …) - Any
Time<...>alias (JulianDate,ModifiedJulianDate, …) chrono::DateTime<Utc>
Sourcepub fn duration_days(&self) -> f64
pub fn duration_days(&self) -> f64
Returns the duration in days as a floating-point value.
This converts the chrono::Duration to days.
Sourcepub fn duration_seconds(&self) -> i64
pub fn duration_seconds(&self) -> i64
Returns the duration in seconds.