[][src]Crate hifitime


Precise date and time handling in Rust built on top of a simple f64. The Epoch used is TAI Epoch of 01 Jan 1900 at midnight.


  • Leap seconds (as announced by the IETF on a yearly basis)
  • Julian dates and Modified Julian dates
  • Clock drift via oscillator stability for simulation of time measuring hardware (via the simulation feature)
  • Ephemeris Time (SPICE ET) / Barycentric Dynamical Time (IERS TDB) computations correct at least to 1e-5 seconds


  • UTC representation with ISO8601 formatting (and parsing in that format)

Almost all examples are validated with external references, as detailed on a test-by-test basis.

Leap second support

Each time computing library may decide when the extra leap second exists as explained in the IETF leap second reference. To ease computation, hifitime decides that second is the 60th of a UTC date, if such exists. Note that this second exists at a different time than defined on NASA HEASARC. That tool is used for validation of Julian dates. As an example of how this is handled, check the Julian day computations for 2015-06-30 23:59:59, 2015-06-30 23:59:60 and 2015-07-01 00:00:00.

Does not include

  • Dates only, or times only (i.e. handles only the combination of both), but the Datetime::{at_midnight, at_noon} help
  • Custom formatting of date time objects
  • An initializer from machine time


Put this in your Cargo.toml:

hifitime = "1"

And add the following to your crate root:

extern crate hifitime;


use hifitime::Epoch;

let mut santa = Epoch::from_gregorian_utc(2017, 12, 25, 01, 02, 14, 0);
assert_eq!(santa.as_mjd_utc_days(), 58112.043217592596);
assert_eq!(santa.as_jde_utc_days(), 2458112.5432175924);

    Epoch::from_gregorian_utc(2017, 12, 25, 02, 02, 14, 0),
    "Could not add one hour to Christmas"


Barycentric Dynamical Time is computed using the ESA Navipedia reference. In three separate examples, the error with SPICE Ephemeris Time is the following: * -9.536743e-07 seconds for 2012-Feb-7 11:22:33 UTC * -3.814697e-06 seconds for 2002-Feb-7 midnight UTC * -4.291534e-06 seconds for 1996-Feb-7 11:22:33 UTC



ClockNoise adds true clock drift to a given Duration measurement. For example, if a vehicle is measuring the time of flight of a signal with high precision oscillator, the engineering specifications will include the oscillator stability. This specification bounds the preciseness of time span calculations. On very short time spans, i.e. less than a few minutes, clock drift is usually negligible. However, in several high fidelity systems the clock drift may lead to a significant error (e.g. several kilometers in two-way radar ranging). This module allows high fidelity simulation systems to test the resilience of algorithms with oscillator stability. The constructors here are specified in parts per million: for a parts per billion specification simply multiply the value by 1e-3. NOTE: Clock stability is not linear. If a clock is rated at stable within 15 ppm per fifteen minute interval this does not correspond to 1 ppm per minute.


Defines an Epoch in TAI (temps atomique international) in seconds past 1900 January 01 at midnight (like the Network Time Protocol).



Errors handles all oddities which may occur in this library.



DAYS_PER_YEAR corresponds to the number of days per year in the Julian calendar.


J1900_OFFSET determines the offset in julian days between 01 Jan 1900 at midnight and the Modified Julian Day at 17 November 1858. NOTE: Julian days "start" at noon so that astronomical observations throughout the night happen at the same Julian day. Note however that the Modified Julian Date (MJD) starts at midnight, not noon, cf. http://tycho.usno.navy.mil/mjd.html.


J2000_OFFSET determines the offset in julian days between 01 Jan 2000 at noon and the Modified Julian Day at 17 November 1858.


Modified Julian Date in seconds as defined here. MJD epoch is Modified Julian Day at 17 November 1858 at midnight.


SECONDS_PER_DAY defines the number of seconds per day.


SECONDS_PER_HOUR defines the number of seconds per hour.


SECONDS_PER_MINUTE defines the number of seconds per minute.


SECONDS_PER_TROPICAL_YEAR corresponds to the number of seconds per tropical year, as defined in tyear_c.c in NAIF SPICE.



Returns true if the provided Gregorian date is valid. Leap second days may have 60 seconds.