Jiff: Datetime library for Rust

Library goals and motivation

  • Jiff is a new Rust datetime library aiming for a more ergonomic, “pit of success” API than existing crates like chrono.
  • Design docs emphasize correct handling of DST, IANA time zones, calendar arithmetic, roundable durations, and lossless round-trips for zoned datetimes.
  • Some see Rust + Chrono as already the best datetime experience they’ve had; others find Chrono correct but rigid and awkward.

API design, traits, and syntax

  • The ToSpan syntax 5.days().hours(8).minutes(1) split opinion; alternatives suggested:
    • Builder-style Span::new().days(5).hours(8).minutes(1)
    • Arithmetic 5.days() + 8.hours() + 1.minutes()
    • Named arguments or struct-default-based patterns, which Rust currently lacks.
  • Discussion of extension traits vs inherent methods: str.parse() uses the standard FromStr trait, with type inferred or specified via turbofish; some prefer Type::parse(str) for explicitness.

Span arithmetic and negative durations

  • Jiff does not overload + for Span + Span; instead uses methods like checked_add, especially when months/years require a reference datetime.
  • Allowing + only for component-wise addition is seen as too subtly different from reference-based addition.
  • Spans can be negative, matching ISO 8601-2 and other libraries. Critics argue physical “durations” should be non-negative; proponents say signed spans model concepts like “1 year ago” and simplify APIs.

Time zones, DST, and Olson/Temporal conventions

  • Several comments highlight how messy real-world time is (DST, scheduling around midnight/weekends, “tomorrow” semantics).
  • Jiff supports IANA zones and the [Olson/Name] suffix pattern used in Temporal and Java’s time APIs to enable lossless round-trips.
  • Some users compare favorably to Python’s pandas and JS’s upcoming Temporal API; others still struggle with timezone conversion ergonomics in Rust.

Leap seconds and TAI vs Unix time

  • Multiple commenters criticize Unix-time-based libraries for ignoring leap seconds and want TAI-first representations.
  • Jiff deliberately omits leap-second-aware core semantics (though TAI-like support via tzif data is possible), arguing:
    • General-purpose apps rarely need full leap-second correctness.
    • Supporting it adds complexity and can introduce more errors than it removes.
  • Scientific and astronomy use cases (e.g., asteroid tracking, precise linking of observations) do need leap-second accuracy; the suggested approach is to use specialized libraries (e.g., TAI/astronomy crates) and interop rather than burden the general-purpose library.

Rust language features and ecosystem

  • Significant side discussion on:
    • Named and optional arguments, struct default fields, and how they might reduce builder boilerplate; proposals exist but are controversial and stalled.
    • Whether Rust should add a datetime type to std; many argue the standard library is intentionally minimal and critical crates should stay outside std to allow evolution.
  • Logging: Jiff uses the log crate as the lowest common denominator; tracing interops but would be heavier.

Error handling and panics

  • Debate over the pervasive use of unwrap()/expect() in Rust:
    • Some view it as culturally overused and worry about panics from deep in dependency trees, especially for long-running or kernel-like code.
    • Others argue panics (fail-fast) are appropriate for invariant violations and can improve reliability by surfacing bugs early; Result + ? is available when recoverability is desired.
  • There is mention of tools like no_panic to enforce non-panicking code and official Rust docs discussing when to panic vs return errors.

Licensing and ecosystem fit

  • Jiff is dual-licensed MIT and Unlicense:
    • Unlicense is seen by its users as an ideological statement against copyright and a “do whatever you want” signal.
    • Others point out Unlicense has legal issues in some jurisdictions, and MIT is added as a pragmatic fallback for corporate/legal comfort.
  • Some commenters argue for copyleft (GPL/LGPL/MPL) to prevent corporate capture; others prefer permissive licenses to avoid forcing downstream code to open-source.

Implementation details and unsafe

  • One code snippet uses from_utf8_unchecked for ASCII-only decimal formatting.
    • A commenter questions whether the micro-optimization justifies added unsafe complexity and potential invariant risk.
    • A micro-benchmark reportedly shows ~15% speedup in that hot path; there is disagreement about the right balance between performance and clarity/safety.

Naming and pronunciation

  • The name “Jiff” and its pronunciation (explicitly defined as like “gif” with a soft g, “gem”) generated lighthearted debate.
  • Some dislike the name as “pretentious” or confusing; others treat the GIF/GIF joke as harmless bikeshedding.

Overall reception

  • Many are enthusiastic, especially given the author’s track record and the depth of the design and comparison docs.
  • Skepticism centers on:
    • Leap-second correctness.
    • Some API choices (method-chained spans, lack of Span + Span).
    • Broader Rust ecosystem issues (no named args, tiny stdlib).
  • Several commenters plan to adopt Jiff in place of Chrono/time; others are content with existing solutions and view Jiff as another strong option rather than an obvious replacement.