Repository navigation
Move dates from chrono to jiff - #19626
Merged
Merged
Conversation
Add `nu_protocol::DateTime`, a jiff timestamp plus the UTC offset it is shown in. Its Display, Debug, RFC 3339, RFC 2822, serde and strftime output match what chrono printed, and its RFC 3339 readers accept what chrono accepted; tests compare it with chrono over a grid of offsets, years, fractions, specifiers and locales. With it, drop the chrono-only crates while `Value::Date` still holds chrono: - chrono-tz: time zone names and offsets come from jiff's database (system tzdata, with the bundled copy as a fallback). - chrono-humanize: `HumanTime` keeps its rough English. - human-date-parser: `date from-human` reads the GNU `date` grammar through parse_datetime after rewriting `at`, `and`, `in N units` and `ago`. - rusqlite's `chrono` feature: dates are written as the same text. - calamine's `dates` feature: spreadsheet dates and durations are converted in nu-command. `format date`, `$env.config.datetime_format`, `into string`, `seq date` and `into datetime --format` use the shared formatter and a jiff strptime pre-pass that keeps their specifier meanings.
…ff, phase 2) `Value::Date`, `Value::date`, `as_date`, `Expr::DateTime`, `Literal::Date` and the `FromValue`/`IntoValue` impls now use `nu_protocol::DateTime` instead of `chrono::DateTime<FixedOffset>`. Every crate that read or built a date moves with it: the parser's date literals, nu-command, nuon, YAML, TOML, KDL, msgpack, plist, history import, nu-mcp and nu-dap. nu-protocol keeps chrono behind an optional `chrono` feature, which adds `From`/`TryFrom`, `FromValue` and `IntoValue` for `chrono::DateTime<FixedOffset>` so plugins can move over gradually. nu_plugin_polars turns it on, since polars' API uses chrono. The text forms do not change: to nuon, to json, to yaml, sqlite text, msgpack bytes and the default display print what they printed with chrono. Two visible differences: `describe --detailed` names the new Rust type, and a leap second (`23:59:60`) reads as `23:59:59`.
Note why the workspace keeps `chrono` and `chrono-humanize`: nu-protocol's optional `chrono` feature and its comparison tests, and nu_plugin_polars. Keep nu-heavy-utils' dependency lists in order. With this, `cargo tree -i chrono -p nu` shows chrono only under rmcp and schemars (nu-mcp), and chrono-tz only under nu_plugin_polars.
`format date --list` and `into datetime --list` now say that `%S` stops at 59, that `%Z` prints the offset because dates keep an offset rather than a zone name, and list `%::z`, `%:::z`, `%N` and `%q`.
Startup: `into datetime` and `date to-timezone` build their time zone completion lists when their signatures are built. Listing jiff's system database walks the zoneinfo directory, which added 12 ms to every `nu` launch (9.2 ms -> 21.2 ms for `nu -n -c 1`). The names now come from jiff's bundled copy, so startup is back to 9.4 ms and every host lists the same 597 names; lookups still prefer the system's data. Speed: date text (RFC 3339, Display, Debug, serde) writes digits directly instead of through `write!`, 157 ns -> 44 ns per `to_rfc3339` (chrono: 42). Strict RFC 3339 parsing validates the date once and checks for a leap second at its fixed position, 26 ns -> 23 ns (chrono: 20). `--format` parsing: comparing 79 formats against main found more chrono rules to keep. `%f` reads its digits as nanoseconds, `%B` and `%A` also read abbreviated names, `%t` and `%n` match any whitespace or none, and a `%C` beside `%Y` or a `%I`/`%l` beside `%H` is read without overriding it. nu-protocol re-exports `pure_rust_locales`, whose `Locale` `DateTime::format` takes, so plugins don't need the crate themselves.
`nu_protocol::DateTime` now holds whole seconds, nanoseconds and an offset itself, so dates cover chrono's years -262143 to 262142 and keep leap seconds, with chrono's arithmetic across them. Formatting renders years outside jiff's range through a 400-year proxy date. `into datetime --format`, `seq date --input-format` and `from kdl` read text with `nu_protocol::ParsedDate`, a port of chrono 0.4.45's strftime parser and field resolver (MIT/Apache-2.0). Fields that disagree, `%s`, `%I` without `%p`, leap seconds and error messages behave as on main. Tests compare it with chrono's four `parse_from_str` functions over every directive alone and in pairs. `date from-human` reads human-date-parser 0.3.1's phrases with a port of its grammar and date arithmetic (MIT) before GNU `date` syntax, so every phrase main read gives the same date. The whole phrase must match, which fixes the phrases it misread or panicked on. Wall-clock times in the system time zone read as chrono's `Local` read them, including the extra second it kept an offset valid past a transition; a time in a DST gap moves forward as it did with chrono. `cal`, `seq date`, msgpack, toml and `touch` use the wider range.
Phase 6 matched main everywhere, including its bugs. This drops the matches that were bugs. - Local wall-clock times read with the same rules as named zones. chrono's `Local` kept an offset valid for a second past a DST change, so `02:00` on a spring-forward day read as `02:00-05:00` and `02:00` after the clock went back read an hour early. Remove `DateTime::chrono_local_readings`. - `into datetime --format` reads a time the clock skips or repeats as `into datetime` does without it: a skipped time moves forward by the jump, a repeated one reads as the earlier. It was an error. - Wall-clock times take the offset in effect on their date: `date to-timezone local`, `into datetime` on a record without `timezone` and `date from-human` used today's offset, and `from xlsx`/`from ods` used the offset of 1970-01-01. - `into datetime --format` and `seq date --input-format` fall back to a smaller reading only when the text lacks fields for the larger one (`ParsedDate::to_wall_clock`). A contradicting or out-of-range field is an error instead of being dropped: `2021-02-30 10:00` gave today at 10:00. An offset in the text places the smaller reading, so `%F %z` is midnight at that offset. - `%Z` reads `UTC`, `GMT` and an offset such as `+05:30`, which is how nushell writes it; other names are an error. It skipped any word, so `PST` read as local time. - `%s` takes a sign, so times before 1970 read back, and a fraction after a negative timestamp counts back from it (`-1.5`). - `date from-human` works out dates on jiff's `ZonedDateTime`: days keep the time of day, hours count real time, and a year from February 29 is February 28. Text after a phrase keeps a time that GNU syntax reads (`today at 6pm blah`); text that doesn't start with a phrase is still no date. - Files with code ported from chrono, chrono-humanize and human-date-parser carry their MIT notices.
…f, phase 8) Fixes from a code review of phase 7, plus seconds limited to 0 to 59. - Second 60, a leap second, is the next minute's second 0 wherever a date is read: literals, `from nuon`, `from toml`, `from kdl`, `into datetime --format`, `seq date` and records. `DateTime` keeps nanoseconds under a second, so `format date`, `into record`, `to toml` and RFC 3339 text never show 60, and `2016-12-31T23:59:60Z` equals `2017-01-01T00:00:00Z`. A record with second 59 and 1,000 ms or more, and msgpack timestamps main wrote for leap seconds, read the same way. Arithmetic is plain nanosecond math, so the port of chrono's leap-second arithmetic and its MIT notice leave `datetime/mod.rs`. `into datetime` without `--format` still rejects `:60`. - `date from-human` keeps a GNU reading's time (`today 1430` is 14:30). Without a phrase at the start, GNU syntax reads the text only with a relative word, `@`, `TZ=` or a time of day, so `6pm tomorrow` and `@1744972472` read and `x`, `est` and `12` don't. - Zone names fall back to jiff's bundled tzdata when the host's lacks them. - `SystemTime` conversions go through Unix nanoseconds, so file times past year 9999 show in `ls`. `to plist` rejects dates outside years 0 to 9999 instead of panicking in the plist crate. - RFC 3339, RFC 2822 and TOML text round an offset with seconds (local mean time) to the minute and move the clock with it, so the text names the same instant. - `into datetime --format` and `seq date` read missing minutes after an hour as 0; `%I` without `%p` is an error instead of midnight. `%J` and `%Q` are parser directives, so `%%J` is literal text. - A record `year` too large for i32 is an error instead of wrapping. - Help text, doc comments and an empty `[dev-dependencies]` cleaned up.
… phase 9) Dates take jiff's range and jiff reads them; nushell keeps chrono's output. - Dates run from year -9999 to 9999, jiff's Timestamp range, so the calendar math and 400-year workarounds go, and `timestamp`, `to_civil` and `to_zoned` can't fail. The hand-written writers stay: jiff writes year -44 as `-044`, and its strftime is slower. - Second 60 reads as 59 everywhere, as jiff reads it, plain `into datetime` included. - `ParsedDate` wraps jiff's strptime (1,313 lines to 172). It keeps chrono's meaning for `%c %x %X %r %v %+ %Z`, `%J` and `%Q`, and offsets with or without colons; jiff reads the rest its own way. `%q` leaves `into datetime --list`. - Date literals, nuon, `FromStr` and serde read RFC 3339 through jiff's `Pieces`, with 4- and 5-digit signed years padded to jiff's 6. - `date from-human` reads GNU syntax through parse_datetime after a few word rewrites, and the human-date-parser port is gone. GNU syntax reads the text only with a time of day, a whole date, a month name or a relative word. - chrono's `From` is now `TryFrom`; a chrono date past 9999 becomes an error value. - One UTC offset reader serves RFC 3339, `parse_utc_offset`, strptime and `date to-timezone` (`parse_zone_offset`). - `DateTime::format` uses the POSIX locale and `format_localized` takes one. `from_civil_local` reads a wall-clock time in the system zone, and `from_civil_in` and `wall_clock_in` drop the disambiguation argument every caller set to compatible. - Tests: the chrono grids cover years -9999 to 9999, every text form reads back over the whole range, and the leap, range and parsing tests follow the new readings.
fdncred
marked this pull request as ready for review
November 21, 2026 17:11
Fixes from a code review of phase 9, and the Windows test failure. - RFC 3339 text with a zone in brackets (`...Z[America/Chicago]`) is no longer read by jiff's `Pieces`, which dropped the zone, so `into datetime` reads it in that zone and a contradicting offset is an error, as on main. - `%Z` reads `UTC` and `GMT` in any case. When an offset specifier gives the offset, `%Z` skips any zone name, as chrono did, so `date '+%F %T %z %Z'` output reads again; `UTC` or `GMT` beside a different offset is an error (`DateParseError::Impossible`). - Date literals and nuon need a `THH:MM` time, so `2024-01-15T10` and `2024-01-15T1030` stay strings. - `cal` builds months from civil dates, so `--full-year 9999` and `-9999` print again. - `%s` keeps the sign of a timestamp under a second (`-0.5`). - Offsets past a day are out of range in RFC 3339 text and `--format`. jiff reads up to 25:59:59; a whole day still reads, since `+23:59:59` writes as `+24:00`. - A record's `timezone` keeps its seconds (`+00:19:32`), so `into record | into datetime` gives back the same instant. - `date from-human` reads a leading `TZ="..."`. - `format date` rounds `%s` down with any flag or width, and `%J` writes negative years as `%Y` does. - `from yaml` reads a `!!timestamp` with second 60 as second 59. - polars rejects dates outside 1677 to 2262 instead of storing 1970-01-01 or null. - `into datetime --list` describes what `%N`, `%::z`, `%:::z` and `%Z` read. - `system_times_round_trip` expects no `SystemTime` before 1601 on Windows, where it counts 100 ns from 1601.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
chrono is unmaintained, so this PR moves nushell's dates to jiff 1.0.
Value::Datenow holdsnu_protocol::DateTime, which stores Unix seconds, nanoseconds and a jiffOffset. It is 16 bytes andCopy, like chrono's type, soValuestays at 48 bytes. jiff does the calendar, time zones, parsing andstrftime. Its range, years -9999 to 9999, is now nushell's.Output only changes where the release notes say so.
Display,Debug, RFC 3339, RFC 2822, serde andformat dateprint what chrono printed, localized names included. Input goes through jiff. Date literals,from nuon,FromStrand serde use its RFC 3339 reader.into datetime --format,seq date --input-formatandfrom kdluse its strptime, plus a small table that keeps chrono's meaning for%c %x %X %r %v %+ %Z, nushell's%Jand%Q, and offsets with or without colons.date from-humanreads GNUdatesyntax through parse_datetime, after a few rewrites such asin 3 daysandovermorrow.chrono-tz, chrono-humanize and human-date-parser leave the dependency tree, along with the chrono features of rusqlite and calamine. chrono stays in
Cargo.lockbecause rmcp and polars use it. The chrono-humanize wording and chrono's UTC offset readers are ported under the MIT license, and each file keeps its notice.Before and after
main is 3d8a9cc. Both ran with
TZ=America/New_Yorkon 2026-11-21 at 13:38. Error cells are cut to the reason.2025-04-18T16:04:32.02649+05:30 | format date '%N'× invalid format026490000'9999-12-31' | into datetime | to nuon9999-12-31T00:00:00-05:00× datetime parsing failed2001-02-03T04:05Z | to nuon× Command 2001-02-03T04:05Z not found2001-02-03T04:05:00+00:002016-12-31T23:59:60.5Z | to nuon2016-12-31T23:59:60.500+00:002016-12-31T23:59:59.500+00:00'Today at 6pm' | date from-human | format date '%H:%M'13:3818:00'today at 6pm blah' | date from-human | format date '%H:%M'13:38× Cannot parse as humanized date'next hour' | date from-human | format date '%H:%M'× Main thread panicked.14:38'6pm tomorrow' | date from-human | format date '%a %H:%M'× Cannot parse as humanized dateSun 18:00'TZ="Europe/Paris" 2025-04-18 04:04' | date from-human | to nuon× Cannot parse as humanized date2025-04-18T04:04:00+02:00'2025-03-09 02:00' | into datetime | to nuon2025-03-09T02:00:00-05:002025-03-09T03:00:00-04:00'2025-03-09 02:30' | into datetime --format '%F %H:%M' | to nuon× datetime parsing failed2025-03-09T03:30:00-04:002026-07-01T16:00:00Z | date to-timezone local | to nuon2026-07-01T11:00:00-05:002026-07-01T12:00:00-04:00'2021-02-30 10:00' | into datetime --format '%F %H:%M' | to nuon2026-11-21T10:00:00-05:00× … parameter 'day' for 2021-02 is invalid, must be in range 1..=28 …'-5' | into datetime --format '%s' | to nuon× can't convert input contains invalid characters …1969-12-31T23:59:55+00:00'07/20/69' | into datetime --format '%D' | to nuon2069-07-20T00:00:00-04:001969-07-20T00:00:00-04:00'Jan 05 2024' | into datetime --format '%B %d %Y' | to nuon2024-01-05T00:00:00-05:00× … %B failed: unrecognized month name …'2021-03-04 10:00 PST' | into datetime --format '%F %H:%M %Z' | to nuon2021-03-04T10:00:00-05:00× can't convert input contains invalid characters …'2021-03-04 10:00:00 -0800 GMT' | into datetime --format '%F %T %z %Z' | to nuon2021-03-04T10:00:00-08:00× can't convert no possible date and time matching input …2100-07-01T12:00:00Z | date to-timezone America/New_York | format date '%:z'-05:00-04:00Release notes
'9999-12-31' | into datetimeis an error, andfrom tomlandfrom msgpackkeep such a date as text.from nuonread2001-02-03T04:05Z,[2024-01-15T10:00]and offsets like+0530and-08as dates.2024-01-15T1030is still a string, and a fraction longer than 9 digits no longer reads.into datetime --format,seq date --input-formatandfrom kdlfollow jiff's strptime. A date that doesn't exist or a weekday that doesn't match is an error, where main gave today at that time.%Band%Atake only full names, and%band%aonly abbreviations. Two-digit years run from 1969 to 2068.%scan be negative, and it wins over a date in the same text.%ZreadsUTC,GMTand offsets. Other names such asPSTare an error, unless%zgives the offset, so+0900 JSTreads.UTCorGMTnext to a different offset, as in-0800 GMT, is an error.format dateand$env.config.datetime_formataccept%N,%#zand the^flag, anddatetime_formatdrops%Eand%Othe wayformat datedoes.seq date --output-formatprints+0000for%zinstead of failing.date from-humanreads GNUdatesyntax:6pm tomorrow,today 1430,@1744972472, and a leadingTZ="Europe/Paris".next month,next hourandtoday at 6pmgive the right date, where main misread them or panicked. Text after a date is an error.--format. Wall-clock times get the offset of their own date, not today's, in records,date to-timezone local,date from-human,from xlsxandfrom ods.timezonekeeps its seconds.yeartoo large for 32 bits is an error, andto plistrejects years before 0 instead of crashing.Value::dateandValue::as_datetakenu_protocol::DateTime. nu-protocol'schronofeature converts to and fromchrono::DateTime<FixedOffset>. Older plugins keep working, since dates cross the wire as the same text.