1 unstable release
0.0.6 | Jan 15, 2023 |
---|---|
0.0.5 |
|
0.0.4 |
|
0.0.3 |
|
0.0.2 |
|
#679 in Unix APIs
25 downloads per month
25KB
501 lines
Geotime
Geotime provides a 128-bit signed integer timestamp compatible with Unix time_t
and anchored at
the Unix epoch. See the documentation here.
use geotime::Geotime;
let dt = Geotime::from(0);
assert_eq!(dt.display_string("%Y-%m-%d"), "1970-01-01");
let dt = Geotime::from((i64::MAX as i128) + 1);
assert_eq!(dt.display_string("%Y"), "299.87 M years from now");
let dt = Geotime::from(-(i64::MAX as i128) * 100);
assert_eq!(dt.display_string("%Y"), "29.99 B years ago");
lib.rs
:
Geotime
Geotime provides a 128-bit signed integer timestamp compatible with Unix time_t
and anchored
at the Unix epoch.
use geotime::Geotime;
let dt = Geotime::from(0);
assert_eq!(dt.display_string("%Y-%m-%d"), "1970-01-01");
let dt = Geotime::from((i32::MAX as i128) * 1000);
assert_eq!(dt.display_string("%Y-%m-%d"), "2038-01-19");
let dt = Geotime::from((i64::MAX as i128) + 1);
assert_eq!(dt.display_string("%Y"), "299.87 M years from now");
let dt = Geotime::from(-(i64::MAX as i128) * 100);
assert_eq!(dt.display_string("%Y"), "29.99 B years ago");
A 128-bit timestamp allows us to represent times of events in astrophysical, geological, historical and present-day timescales to millisecond precision. We go down to milliseconds as a convenience for handling timestamps for recent events. In order to maintain a clean mapping to Unix timestamps, Geotime inherits whatever is going on with leap seconds. Timestamps can represent any date within +- 5e27 years of 1970.
Several serialization formats are provided that preserve lexical ordering of timestamps.
This project is rough at this point, and it is probably easy to trigger a panic. The plan is to gradually replace panics with errors, but it might be a while.
Dependencies
~3.5MB
~68K SLoC