std::time¶
Status: experimental
Wall-clock and monotonic time facilities.
API details and source¶
The implementation source contains the complete declarations and implementation notes. The table below lists canonical Gossamer call signatures; every item name links directly to its implementation file.
| Item | Canonical signature or declaration | Description |
|---|---|---|
Duration |
type Duration |
Difference between two Instants. |
Instant |
type Instant |
Monotonic point-in-time. |
SystemTime |
type SystemTime |
Wall-clock point-in-time. |
CivilTime |
type CivilTime |
Calendar fields interpreted with an explicit location. |
CivilResolution |
enum CivilResolution { Unique(i64), Gap, Fold(i64, i64) } |
Explicit civil-to-timeline resolution. |
Location |
type Location |
Immutable UTC, fixed-offset, or IANA time-zone location. |
add_date |
fn add_date(unix_ms: i64, location: Location, years: i64, months: i64, days: i64) -> Result<i64, errors::Error> |
Calendar addition that rejects gap and fold results. |
format_in |
fn format_in(layout: String, unix_ms: i64, location: Location) -> Result<String, errors::Error> |
Formats an instant in an explicit location. |
format_rfc3339 |
fn format_rfc3339(ms: i64) -> Result<String, errors::Error> |
Formats a SystemTime in RFC 3339 (YYYY-MM-DDTHH:MM:SSZ). |
monotonic_ms |
fn monotonic_ms() -> i64 |
Monotonic clock reading in milliseconds. |
monotonic_nanos |
fn monotonic_nanos() -> i64 |
Monotonic clock reading in nanoseconds. |
now |
fn now() -> time::Instant |
Returns the current monotonic Instant. |
now_ms |
fn now_ms() -> i64 |
Wall-clock milliseconds since the Unix epoch. |
now_nanos |
fn now_nanos() -> i64 |
Wall-clock nanoseconds since the Unix epoch. |
parse_rfc3339 |
fn parse_rfc3339(text: String) -> Result<i64, errors::Error> |
Parses an RFC 3339 timestamp into a SystemTime. |
since_ms |
fn since_ms(instant: time::Instant) -> i64 |
Milliseconds elapsed since an earlier monotonic reading. |
sleep |
fn sleep(ms: i64) -> () |
Suspends the current goroutine for Duration. |
unix_ms |
fn unix_ms() -> i64 |
Current Unix time in milliseconds. |
use std::time
let ny = time::Location::lookup("America/New_York")?
let local = ny.civil(-1)?
match ny.resolve(local)? {
time::CivilResolution::Unique(ms) => println!("{}", ms),
time::CivilResolution::Gap => println!("nonexistent local time"),
time::CivilResolution::Fold(earlier, later) => println!("{} {}", earlier, later),
}