jflib-datetime 0.2.2

Calendar time without std: timestamps, civil dates, RFC 3339, time zones, cron schedules
Documentation
  • Coverage
  • 68.35%
    54 out of 79 items documented0 out of 61 items with examples
  • Size
  • Source code size: 91.2 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.7 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 4s Average build duration of successful builds.
  • all releases: 7s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • JFLibrary/JFLib
    3 2 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Graphsto

jflib-datetime

Calendar time for JFLib, without the standard library and without a line of unsafe code: timestamps, calendar dates, ISO weeks, RFC 3339 text, time zones with daylight saving time, and cron schedules. It has no clock of its own and only computes, so it gives the same answers on every machine.

What it does

A Timestamp is a point in time, seconds and nanoseconds since 1970 in UTC. A Civil is a calendar date and wall time without a zone (Civil::from_unix and to_unix convert), and free functions answer the calendar questions: leap years, the days of a month, the weekday, the ISO 8601 week of a date and the Monday of a week. rfc3339 and parse_rfc3339 write and read the timestamps of logs and protocols, format_date_time, format_duration and format_relative the texts people read (in German or English).

Zone knows the zones of the IANA time zone database by name, each with its current rule for daylight saving time, maps Windows' time zone names to them, and also takes a POSIX TZ string or a TZif file such as /etc/localtime. It turns a timestamp into local time and back. Going back is the hard direction, and from_local says so honestly: a wall time is Single, Ambiguous in the hour the clocks repeat, or falls into the Gap when they jump forward.

Cron reads five-field cron expressions, with month and weekday names and shortcuts such as @daily, and finds the next runs in a zone. A run that falls into a skipped hour happens right after the jump, one in a repeated hour happens once. describe puts a schedule into words.

use jflib::{datetime, plat};
use datetime::{Cron, Timestamp, Zone};

let now = Timestamp::from_nanos(plat::unix_time_ns());
let berlin = Zone::by_name("Europe/Berlin").unwrap_or_else(Zone::utc);
let stamp = datetime::rfc3339(now);                          // "2026-11-13T09:30:00.123Z"
let shown = datetime::format_date_time(now, &berlin, true);  // "2026-11-13 10:30"
if let Ok(cron) = Cron::parse("30 2 * * 1-5") {
    let next = cron.next_after(now, &berlin);                // the next weekday at 02:30 in Berlin
    let words = cron.describe(true);                         // "Weekdays at 02:30"
}

A zone describes its offsets from its last rule change on: times before that change are computed with today's rule. That suits schedules, logs and displays of the present, not historical records.

How to get it

Like all of JFLib, the crate comes through the one dependency jflib, as jflib::datetime. All of JFLib's crates share one version and are released together. It runs on every platform JFLib supports.

What's new in 0.2.2

Nothing in this crate. It is released again as 0.2.2 only because all of JFLib's crates move together. The changelog says the same.

Documentation

License

MIT or Apache-2.0, at your choice. The table that maps Windows' time zone names to IANA zones comes from the Unicode CLDR and is also under the Unicode License v3.