Expand description
Unix timestamp conversions between epoch seconds and human-readable UTC strings.
Converts Unix epoch values (seconds or milliseconds) to ISO 8601 UTC strings and back, using pure Rust standard library arithmetic — no external time crates. Handles the full signed 32-bit year range, including negative timestamps (dates before 1970-01-01).
§Features
now_secs— current Unix timestamp in seconds.now_millis— current Unix timestamp in milliseconds.to_utc_string— epoch seconds →"YYYY-MM-DDTHH:MM:SSZ".from_utc_string—"YYYY-MM-DDTHH:MM:SSZ"→ epoch seconds.EpochError— structured error for invalid datetime strings.
§Quick Start
use rune_epoch::{to_utc_string, from_utc_string};
assert_eq!(to_utc_string(0), "1970-01-01T00:00:00Z");
assert_eq!(from_utc_string("1970-01-01T00:00:00Z").unwrap(), 0);§CLI
rune-epoch # print current epoch
rune-epoch 1704067200 # convert epoch to UTC
rune-epoch --millis # print current epoch in milliseconds
rune-epoch "2024-01-15T14:30:00Z" # parse datetime string to epochEnums§
- Epoch
Error - Error returned when
from_utc_stringcannot parse its input.
Functions§
- days_
in_ month - Returns the number of days in
monthfor the givenyear. - from_
utc_ string - Parses a UTC datetime string and returns the Unix epoch in seconds.
- is_
leap_ year - Returns
truewhenyearis a leap year in the proleptic Gregorian calendar. - now_
millis - Returns the current Unix timestamp in milliseconds.
- now_
secs - Returns the current Unix timestamp in whole seconds.
- to_
utc_ string - Converts a Unix epoch (seconds) to a UTC datetime string in ISO 8601 format.