Skip to main content

Module time

Module time 

Source
Expand description

Wall-clock conversion, parsing, and duration-formatting utilities.

The helpers convert between SystemTime and the Unix epoch, parse human-readable durations, and choose display units. These clocks are not monotonic and can be affected by system-time changes.

Re-exportsยง

use std::time::Duration; ๐Ÿ”’
use std::time::SystemTime; ๐Ÿ”’
use std::time::UNIX_EPOCH; ๐Ÿ”’
pub use elapsed::Elapsed;
use crate::Result; ๐Ÿ”’
use crate::err; ๐Ÿ”’

Modulesยง

elapsed ๐Ÿ”’
exponential_backoff
Retry-backoff calculations.

Enumsยง

Unit
Represents an integral duration in one selected unit.

Functionsยง

deadline_has_passed
Checks whether an optional deadline has passed.
duration_since_epoch
Converts a system time into a nonnegative duration since the Unix epoch.
format
Formats a system time in UTC with a Chrono format string.
millis
Converts a duration to whole milliseconds when they fit in a u64.
now
Returns the current wall-clock duration since the Unix epoch.
now_millis
Returns the current wall-clock time as whole milliseconds since the Unix epoch.
now_secs
Returns the current wall-clock time as whole seconds since the Unix epoch.
parse_duration
Parses a human-readable duration with the cyborgtime parser.
parse_timepoint_ago
Parses a duration and returns the wall-clock time that far in the past.
pretty
Formats a duration with one plural human-readable unit.
rfc2822_from_seconds
Formats a signed Unix timestamp as RFC 2822 text in UTC.
timepoint_ago
Subtracts a duration from the current wall-clock time using checked arithmetic.
timepoint_from_epoch
Adds a duration to the Unix epoch using checked arithmetic.
timepoint_from_now
Adds a duration to the current wall-clock time using checked arithmetic.
timepoint_has_passed
Checks whether a system time is at or before the current wall-clock time.
whole_and_frac
Pairs a durationโ€™s selected whole unit with its fraction in [0, 1).
whole_unit
Selects the largest integral unit represented by a duration.