Skip to main content

Crate rune_epoch

Crate rune_epoch 

Source
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 epoch

Enums§

EpochError
Error returned when from_utc_string cannot parse its input.

Functions§

days_in_month
Returns the number of days in month for the given year.
from_utc_string
Parses a UTC datetime string and returns the Unix epoch in seconds.
is_leap_year
Returns true when year is 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.