Skip to content

Replace chrono with jiff in the Rust SDK - #311

Merged
jeremy merged 4 commits into
mainfrom
chore/replace-chrono-with-jiff
Nov 20, 2026
Merged

jeremy merged 4 commits into
mainfrom
chore/replace-chrono-with-jiff

Conversation

@jeremy

@jeremy jeremy commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

RUSTSEC-2026-0543 marks chrono unmaintained, and #307 put it on cargo-deny's ignore list until replacing it could be its own release. This is that change: the Rust SDK moves to jiff 1.x, and the ignore comes out. basecamp/basecamp-sdk#1106 makes the same change there.

Why jiff, and why now

  • chrono's maintainer soft-deprecated it in January (Soft-deprecating chrono and chrono-tz chronotope/chrono#1768), declined a handover, and held the advisory "until after the jiff 1.0 release". jiff 1.0 shipped 2026-11-15 with "an indefinite commitment to 1.x.y. Consumers of this library should feel confident about putting Jiff types into their public API." The floor is 1.0.1 (which fixes an out-of-bounds timestamp parse). Its MSRV is 1.85, under our 1.88, so rust-version doesn't move.
  • time was the other candidate. It is still 0.x and has no tz database, which Date::today and from_datetime_in need. Its OffsetDateTime serde isn't RFC 3339, so every generated field would need a with attribute.
  • The crate has no reverse dependencies on crates.io.

What changes

Was Now
DateTime = chrono::DateTime<Utc> jiff::Timestamp
Date(pub chrono::NaiveDate) Date(pub jiff::civil::Date)
<Date as FromStr>::Err = chrono::ParseError jiff::Error
Date::from_datetime_in<Tz: chrono::TimeZone> from_datetime_in(&DateTime, &jiff::tz::TimeZone)
Date::at_midnight_utc() -> DateTime -> Option<DateTime> (None only for 9999-12-31)
chrono::Weekday in Date::weekday and Identity::set_first_week_day jiff::civil::Weekday
Token::expires_at: Option<DateTime<Utc>> Option<jiff::Timestamp>
(none) pub use jiff;

The generator only names crate::types::{Date, DateTime}, so no generated code changes. MIGRATING.md has the upgrade notes.

What stays the same, and how it was checked

  • Instants. I compared chrono's DateTime<Utc> serde with jiff's Timestamp serde. They agree on Z, numeric offsets, a space separator, lowercase t/z and nine fractional digits. Both refuse a missing offset and a bare date. Output is byte-identical. They differ only at the edges: a leap second reads as :59, and more than nine fractional digits is refused.
  • Dates. jiff's own date parser accepts 20260304 and 2026-03-04T00:00:00. Date therefore parses with strptime("%Y-%m-%d"), which matches chrono's %Y-%m-%d, unpadded 2026-3-4 included. tests/dates.rs now refuses both of those wider forms. Date::default() stays 1970-01-01 (jiff's own default is year zero). add_months/add_years keep Go's AddDate rollover, which jiff's clamping arithmetic would not.
  • Date::today(). jiff reads the zone with tz-system. Without a tz database it would silently fall back to UTC for a TZ=America/Chicago setting and on Windows and Android, so the crate enables tzdb-zoneinfo, tzdb-bundle-platform and tzdb-concatenated. Checked against chrono::Local with TZ unset, Pacific/Kiritimati, Etc/GMT+12 and an unknown zone: the same date in all four.
  • Retry-After. jiff::fmt::rfc2822::parse agreed with chrono::DateTime::parse_from_rfc2822 on 14 of 14 forms. Those covered GMT, UT, EST, PDT, Z and military zones, a missing weekday, two-digit years, missing seconds, a wrong weekday (refused by both), extra spaces, lowercase and a (UTC) comment.
  • Stored OAuth tokens. expires_at is RFC 3339 UTC either way.
  • make rs-check rs-check-drift rs-consumer-check passes locally: lint, tests, docs, cargo deny (advisories ok with an empty ignore list) for both workspaces, generated code up to date, and the consumer build with and without default features.

cargo semver-checks will flag the break; the breaking label is on.


Summary by cubic

Replaces the deprecated chrono crate with jiff 1.x in the Rust SDK, and drops the cargo-deny ignore for RUSTSEC-2026-0543. The wire format is unchanged — instants stay RFC 3339 and dates stay YYYY-MM-DD — so stored OAuth tokens read back as before, and no generated code changes. This is a breaking release; MIGRATING.md has the before-and-after table.

Migration

  • DateTime is jiff::Timestamp, Date wraps jiff::civil::Date, and the crate re-exports hey_sdk::jiff.
  • Date::from_datetime_in takes a jiff::tz::TimeZone, and Date::at_midnight_utc returns Option<DateTime>, None at the calendar's ends.
  • Weekdays are spelled out: Weekday::Monday instead of Weekday::Mon.
  • Date still parses only %Y-%m-%d, Date::default() stays 1970-01-01, and add_months/add_years keep Go's AddDate rollover.
  • Date now prints through the same %Y-%m-%d it reads, so dates before year 0 still round-trip.

Written for commit a615987. Summary will update on new commits.

View guided diff Turn on auto-fix

chrono is unmaintained (RUSTSEC-2026-0543; its maintainer wound it down
and pointed at jiff, and held the advisory for jiff 1.0, now out). The
crate's dates and instants move to jiff 1.x, which commits to a stable
1.x API, and the advisory comes off cargo-deny's ignore list.

- `DateTime` is `jiff::Timestamp`; `Date` wraps `jiff::civil::Date`;
  the crate re-exports `hey_sdk::jiff`.
- The wire format is unchanged: RFC 3339 in, UTC with `Z` out, and
  `YYYY-MM-DD` dates. `Date` still parses with `%Y-%m-%d` rather than
  jiff's wider parser, which takes `20260304` and a datetime whose time
  it drops, and `Date::default()` stays 1970-01-01.
- `Date::from_datetime_in` takes a `jiff::tz::TimeZone`; `weekday()` and
  `Identity::set_first_week_day` use `jiff::civil::Weekday`;
  `at_midnight_utc()` answers `Option`, since 9999-12-31's midnight is
  past jiff's last instant. `add_months` keeps Go's rollover.
- `Date::today()` reads the system zone with jiff's tz-system and the
  platform's time zone database (bundled on Windows), so `TZ` names and
  Windows and Android zones resolve as they did with chrono's `Local`.
- Retry-After's RFC 2822 date parses with jiff, which agrees with
  chrono on every form probed. OAuth `Token::expires_at` is
  `Option<jiff::Timestamp>`; stored tokens read back as before.

The generator only names `crate::types::{Date, DateTime}`, so no
generated code changes. MIGRATING.md has the before-and-after table.
Copilot AI balanced review requested due to automatic review settings November 19, 2026 22:45

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Negative-year dates fail to round-trip through JSON because serialization emits six year digits while the parser accepts at most four, requiring consistent formatting and a regression test.

1 open issue
What changed in this PR

Replaces chrono with jiff 1.x in the Rust SDK, completing the migration deferred in #307 and removing the temporary advisory exception. This changes public date/time types without changing generated code.

Changes:

  • Migrates dates, timestamps, weekdays, OAuth expiry, and retry timing to jiff.
  • Updates dependencies, tests, and the OAuth example.
  • Documents breaking API changes and re-exports jiff for consumers.

[!TIP]
If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.

File Description
rust/​hey-sdk/​tests/​services_identity.rs Uses jiff weekday variants.
rust/​hey-sdk/​tests/​retry_policy.rs Builds retry dates with jiff.
rust/​hey-sdk/​tests/​dates.rs Migrates date tests and adds parsing checks.
rust/​hey-sdk/​tests/​body_limit.rs Updates retry-date test setup.
rust/​hey-sdk/​src/​types.rs Replaces core date/time types and arithmetic.
rust/​hey-sdk/​src/​services/​time_tracks.rs Uses jiff for stop timestamps.
rust/​hey-sdk/​src/​services/​identity.rs Migrates weekday mappings to jiff.
rust/​hey-sdk/​src/​oauth.rs Migrates token expiry timestamps and calculations.
rust/​hey-sdk/​src/​lib.rs Re-exports jiff for SDK consumers.
rust/​hey-sdk/​src/​error.rs Migrates Retry-After parsing and duration calculations.
rust/​hey-sdk/​examples/​oauth_pkce.rs Updates expiry timestamp formatting.
rust/​hey-sdk/​Cargo.toml Replaces chrono with jiff and time-zone features.
rust/​deny.toml Removes the chrono advisory exception.
rust/​Cargo.lock Records the SDK dependency migration.
MIGRATING.md Documents public API changes and upgrade guidance.
conformance/​runner/​rust/​Cargo.lock Synchronizes conformance runner dependencies.

Review effort: Balanced

Comment thread rust/hey-sdk/src/types.rs Resolved
jiff's Display writes a negative year with six digits (-000001), which
the %Y-%m-%d that Date reads does not take, so such a date no longer
round-tripped through JSON as it did with chrono. Display now formats
with the same %Y-%m-%d; for years 0 to 9999 the output is unchanged.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The documentation omits None results for -9999-01-01 and -9999-01-02 in both types.rs and MIGRATING.md, leaving callers unaware of lower-bound timestamp failures.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Low severity Document all dates below Jiff's minimum timestamp

rust/​hey-sdk/​src/​types.rs:87

None also occurs for -9999-01-01 and -9999-01-02, whose UTC midnights fall below jiff's minimum timestamp. Document all three dates so callers do not treat the lower-bound failures as impossible. The same correction is needed in MIGRATING.md:22.

1 resolved since last review

Review effort: Balanced

… too

Timestamp::MIN is -9999-01-02T01:59:59Z, so -9999-01-01 and -9999-01-02
have no midnight UTC either; the doc and MIGRATING named only
9999-12-31. A test pins all three and the days beside them.
@jeremy

jeremy commented Nov 19, 2026

Copy link
Copy Markdown
Member Author

Fixed in a615987 (review). Timestamp::MIN is -9999-01-02T01:59:59Z, so -9999-01-01 and -9999-01-02 have no midnight UTC either. at_midnight_utc's doc and the MIGRATING row now name all three. only_the_calendar_ends_have_no_midnight_utc pins the three Nones and the days beside them, -9999-01-03 and 9999-12-30.

@jeremy

jeremy commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

Review threads: 1 resolved (1 fixed). The negative-year round-trip was fixed in fb681ee.
Review bodies: 1 finding answered (1 fixed).
Fixed from a review body: at_midnight_utc's None cases. The doc, MIGRATING and a test now name -9999-01-01, -9999-01-02 and 9999-12-31 (a615987).
Not reported on the head: Copilot, on a615987. It was re-requested once after the empty CodeQL-rerun commit 5ca52fd. a615987 changes only a doc comment, a MIGRATING row and a test.

@jeremy
jeremy merged commit 3526d29 into main Nov 20, 2026
35 checks passed
@jeremy
jeremy deleted the chore/replace-chrono-with-jiff branch November 20, 2026 00:02
@jeremy jeremy mentioned this pull request Nov 20, 2026
jeremy added a commit that referenced this pull request Nov 20, 2026
Release bump for 0.36.0 (make bump VERSION=0.36.0): chrono replaced by jiff in Rust (#311), and UndoTopicSend and RestoreEntry (#312).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants