Crate hifitime [] [src]

hifitime 0.0.1

Precise date and time handling in Rust built on top of std::time::Duration. The Epoch used is TAI Epoch of 01 Jan 1900 at midnight, but that should not matter in day-to-day use of this library.

Features

  • Leap seconds (as announced by the IETF on a yearly basis)
  • Julian dates and Modified Julian dates
  • UTC representation with ISO8601 formatting
  • Allows building custom TimeSystem (e.g. Julian days)
  • Time varying TimeZones to represent static or very high speed reference frames (cf. the tz test in the tests module)

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)
  • Custom formatting of date time objects
  • An initializer from machine time
  • A simple to use TimeZone offset

The validation tools used generate very long URLs, which aren't supported by rustfmt. As such, whenever a validation link is provided, it has been shortened using Google's http://goo.gl service. If this is an issue, please add info/ between goo.gl/ and the unique identifier: this will allow you to see the redirection link prior to being redirected (as well as the link analytics). For example, https://goo.gl/o3KXSR becomes https://goo.gl/info/o3KXSR.

Usage

Put this in your Cargo.toml:

[dependencies]
hifitime = "0.0.1"

And add the following to your crate root:

extern crate hifitime;

Examples:

use hifitime::utc::{Utc, TimeZone, TimeSystem};
use hifitime::instant::Duration;
use hifitime::julian::ModifiedJulian;

let santa = Utc::new(2017, 12, 25, 01, 02, 14, 0).expect("Xmas failed");

assert_eq!(
    santa.into_instant() + Duration::new(3600, 0),
    Utc::new(2017, 12, 25, 02, 02, 14, 0)
        .expect("Xmas failed")
        .into_instant(),
    "Could not add one hour to Christmas"
);
assert_eq!(format!("{}", santa), "2017-12-25T01:02:14+00:00");
assert_eq!(
    ModifiedJulian::from_instant(santa.into_instant()).days,
    58112.043217592596
);
assert_eq!(
    ModifiedJulian::from_instant(santa.into_instant()).julian_days(),
    2458112.5432175924
);

Modules

instant

The instant module is built on top of std::time::Duration. It is the basis of almost all computations in this library. It is the only common denominator allowing for conversions between Time Systems.

julian

The julian module supports (Modified) Julian Days, which are heavily used in astronomy and its engineering friends.

utc

The Utc module supports conversions between Utc and other time systems. The main advantage (and challenge) is the inherent support for leap seconds. Refer to module documentation for leap second implementation details.

Enums

Errors

Errors handles all oddities which may occur in this library.

Traits

TimeSystem

A TimeSystem enables the creation of system for measuring spans of time, such as UTC or Julian days.