Skip to content

Fix getDateTimeLocalValue() for epoch numbers and Date values - #5397

Merged
heath-freenome merged 10 commits into
rjsf-team:v7from
drakeo338:claude/5393-fix
Oct 4, 2026
Merged

heath-freenome merged 10 commits into
rjsf-team:v7from
drakeo338:claude/5393-fix

Conversation

@drakeo338

@drakeo338 drakeo338 commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Reasons for making this change

Fixes #5393.

getDateTimeLocalValue() returned an undefined localValue for anything that was not a string, so a date-time field holding an epoch number or a Date rendered empty. A finite number or a valid Date is now converted as follows:

  • date-time/datetime: the UTC ISO string, which the themes parse as an instant.
  • date: a UTC midnight comes back as the day it names (YYYY-MM-DD); any other instant gets local wall-clock time.
  • Every other format, including iso-date-time: local wall-clock time via utcToLocal().

Invalid dates, non-finite numbers and other types still give undefined. The daisyui DateTimeWidget now reads only the getDateTimeLocalValue() result.

Checklist

  • I'm updating documentation
  • I'm adding or updating code
    • I've added and/or updated tests. I've run pnpm exec nx run-many --target=build --exclude=@rjsf/docs && pnpm run test:update to update snapshots, if needed.
    • I've updated docs if needed
    • I've updated the changelog with a description of the PR
  • I'm adding a new feature
    • I've updated the playground with an example use of the feature

Unticked items do not apply (no docs or feature change). I ran the utils, core, antd, mantine and daisyui tests plus lint; I did not run the snapshot build.

@heath-freenome heath-freenome left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for picking this up! The date-time path is right. antd, mantine and daisyui now receive a UTC ISO string, which they parse as an instant and display in local time. The invalid-input cases (NaN, Infinity, out-of-range numbers, invalid Dates) are covered, and the CHANGELOG entry is in the right place.

One note on the issue itself: core's DateTimeWidget only reads localValue for iso-date-time. For date-time it passes the raw value to utcToLocal(), which already handled numbers and Dates. So in core only iso-date-time fields were rendering empty.

The inline comment is the one change needed. For iso-date-time, an epoch or Date is currently shown at its UTC time as if it were local, so editing the field saves a time that is off by the user's UTC offset.

Also:

  • CI hasn't run on this PR yet, because the workflows need a maintainer's approval for a first-time contributor.
  • There's a trivial conflict in CHANGELOG-v7.md with v7.

stringValue = value;
} else if (typeof value === 'number' || value instanceof Date) {
const date = new Date(value);
stringValue = Number.isNaN(date.getTime()) ? undefined : date.toISOString();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is right for date-time, but not for iso-date-time. An epoch number or a Date is an exact moment in time, and toISOString() gives that moment's UTC wall-clock time. offsetTimeToLocalTime() then only strips the trailing Z; it doesn't convert anything. Every theme treats an iso-date-time localValue as local time (daisyui's commitValue calls it a "naive local date-time string"). So the field shows the UTC time as if it were local. In America/Los_Angeles:

stored instant (UTC)        : 2020-05-03T14:30:00.000Z
this PR (iso-date-time)     : 2020-05-03T14:30:00.000
  ...read back as local time: 2020-05-03T21:30:00.000Z   <- 7h later than stored
utcToLocal() would give     : 2020-05-03T07:30:00.000
  ...read back as local time: 2020-05-03T14:30:00.000Z

The field shows 14:30 for a moment that is 07:30 locally. If the user edits just the day, the value saved back is 7 hours off. That's the same silent replacement of a stored instant that #5393 describes, just harder to notice than an empty field.

For iso-date-time, a number or Date needs the local wall-clock time instead, which utcToLocal() already produces in the same yyyy-MM-ddThh:mm:ss.SSS shape. For example:

} else if (typeof value === 'number' || value instanceof Date) {
  const date = new Date(value);
  if (!Number.isNaN(date.getTime())) {
    const iso = date.toISOString();
    return { isIsoDateTime, localValue: isIsoDateTime ? utcToLocal(iso) : iso };
  }
}

The two new iso-date-time tests currently expect the UTC time, and they pass in any time zone only because nothing in them depends on the local zone. With this change they'd depend on it, so they'd need a pinned zone, like the helper in packages/daisyui/test/helpers/pinTimeZone.ts. Ideally pin a zone that isn't UTC, so the test actually catches this.

(A string value that includes a Z or an offset also has its offset stripped without conversion under iso-date-time. That behavior predates this PR and is out of scope here.)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in 79a94a0: iso-date-time now shows an epoch or Date at local wall-clock time via utcToLocal(), the tests pin America/Los_Angeles so they catch it, and the CHANGELOG conflict with v7 is resolved.

@github-actions

github-actions Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Size limit report

Sizes are minified + brotli, measured by size-limit at 7bc3f34.

A package listed twice is measured both as installed and, on the second row, as its own code with its dependencies excluded. Peer dependencies are always excluded.

Check Base PR Δ
@rjsf/antd 7.14 kB 7.14 kB =
@rjsf/antd (without dependencies) 6.73 kB 6.73 kB =
@rjsf/chakra-ui 18.69 kB 18.69 kB =
@rjsf/chakra-ui (without dependencies) 10.67 kB 10.67 kB =
@rjsf/core 26.84 kB 26.84 kB =
@rjsf/core/markdown 25.53 kB 25.53 kB =
@rjsf/core/testing 59.15 kB 59.15 kB =
@rjsf/core: Form 26.68 kB 26.68 kB =
@rjsf/daisyui 53.66 kB 53.57 kB -0.10 kB
@rjsf/daisyui (without dependencies) 10.75 kB 10.74 kB -0.01 kB
@rjsf/fluentui-rc 5.74 kB 5.74 kB =
@rjsf/mantine 14.28 kB 14.29 kB +0.01 kB
@rjsf/mantine (without dependencies) 9.92 kB 9.95 kB +0.03 kB
@rjsf/mui 6.54 kB 6.54 kB =
@rjsf/react-bootstrap 7.73 kB 7.73 kB =
@rjsf/react-bootstrap (without dependencies) 5.29 kB 5.29 kB =
@rjsf/shadcn 43.40 kB 43.40 kB =
@rjsf/shadcn (without dependencies) 9.10 kB 9.10 kB =
@rjsf/utils 26.50 kB 26.60 kB +0.10 kB
@rjsf/utils (without dependencies) 20.88 kB 20.96 kB +0.09 kB
@rjsf/utils: getUiOptions 0.54 kB 0.54 kB =
@rjsf/validator-ajv8 38.12 kB 38.12 kB =
@rjsf/validator-ajv8 (without dependencies) 2.65 kB 2.65 kB =
@rjsf/validator-ata 86.26 kB 86.26 kB =
@rjsf/validator-ata (without dependencies) 2.42 kB 2.42 kB =
@rjsf/validator-cfworker 7.22 kB 7.22 kB =
@rjsf/validator-cfworker (without dependencies) 2.32 kB 2.32 kB =

@heath-freenome heath-freenome left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the quick turnaround. The iso-date-time fix is exactly what I was after, and pinning America/Los_Angeles in the tests means they'll catch it if it regresses.

A few things are still open:

  • The CHANGELOG conflicts with v7 again. It was resolved when you pushed, but since then #5381, #5386, #5400 and #5364 have added bullets at the end of the ## @rjsf/utils section, and git merge-tree reports a conflict there. Please rebase and put the #5393 bullet after them.
  • The comment in packages/daisyui/src/widgets/DateTimeWidget/DateTimeWidget.tsx (around line 80) is now wrong. It's outside this diff, so I'm noting it here. It says a non-string value gives getDateTimeLocalValue() "nothing … to return", but after this PR it returns a string for every finite number and valid Date. On that path the localValue ?? value fallback, and readInstant's handling of numbers and Dates, now only ever get values that are rejected anyway. Please update the comment, and drop the fallback if nothing else needs it.

Comment thread CHANGELOG-v7.md Resolved
@drakeo338

Copy link
Copy Markdown
Contributor Author

Rebased onto current v7 with the #5393 changelog bullet after the four new ones; updated the DateTimeWidget comment and dropped the localValue ?? value fallback, which nothing else needed.

@heath-freenome heath-freenome left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the rebase and the daisyui cleanup. The corrected comment reads right, and dropping the localValue ?? value fallback is safe. readInstant still needs its number and Date handling for daisyui's DateWidget, and the existing epoch and Date cases in DateTimeWidget.test.tsx now go through getDateTimeLocalValue() and pass.

The three inline comments from my last review are still open, and I've replied on each:

  • the requiresOffset change, including a correction to how the bug shows up in Mantine
  • the JSDoc
  • the CHANGELOG wording, which also conflicts with v7 again

Two smaller things:

  • The PR description still says a number or Date goes "through the same offset handling as a string value". For iso-date-time it's now converted to local time instead, and the requiresOffset change will extend that to every format except date-time/datetime.
  • Optional: getDateTimeLocalValue() could return early for a string, then handle a number or Date, then return undefined, instead of carrying stringValue through to a second check.

…teTimeLocalValue()

getDateTimeLocalValue() returned an undefined localValue for anything but
a string, so a date-time field holding an epoch number or a Date rendered
empty. A finite number or a valid Date now becomes its ISO string, then
goes through the same iso-date-time offset strip as a string value. An
invalid Date, a non-finite or out-of-range number, and any other
non-string value still give undefined.
@drakeo338

Copy link
Copy Markdown
Contributor Author

Thanks, all four are done. getDateTimeLocalValue() now keeps the UTC ISO string only for date-time/datetime and shows every other format at local wall-clock time, with tests for no format and format: 'date' under the pinned America/Los_Angeles zone; it also returns early for a string, then handles a number or Date. The JSDoc is wrapped under 120 characters and describes the epoch/Date conversion. I rebased onto v7, put the #5393 bullet after the new @rjsf/utils bullets in your wording, and corrected the PR description.

@heath-freenome heath-freenome left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, this round covers everything I asked for:

  • the requiresOffset split
  • the tests for a field with no format and one with format: 'date'
  • the JSDoc and the CHANGELOG
  • the early return and the updated description

The conflict with v7 is gone too.

Re-reviewing the new head turned up a few more things. Two of them come from changes I asked for, so sorry for the extra round:

  • Inline comments:
    • format: 'date' now shows different days in different themes
    • the hour when clocks go back in daisyui
    • the daisyui comment
    • years outside 0–9999 (minor)
  • Docs: packages/docs/docs/api-reference/utility-functions.md (line 762) repeats the function's JSDoc, and still describes only the offset stripping. Please add the new paragraph about epoch numbers and Dates there too.
  • Optional: Mantine's DateTimeInput.tsx (line 79) repeats the same date-time/datetime check. Returning it as a requiresOffset field on DateTimeLocalValueResult would keep the two from drifting apart. This is fine as a follow-up.

… requiresOffset

- format: date reads an epoch or Date at UTC midnight as the day it names, matching daisyui
- an epoch or Date whose local year is outside 0-9999 gives undefined
- daisyui reads a non-text value as an instant, so the repeated 01:30 is kept
- DateTimeLocalValueResult returns requiresOffset, which mantine now uses
- document epoch numbers and Dates in the utility-functions reference
@drakeo338

Copy link
Copy Markdown
Contributor Author

Thanks, all in the new commit. Under format: 'date' an epoch or Date at UTC midnight now reads as the UTC day (your snippet), so the themes agree; a local year outside 0-9999 returns undefined; DateTimeLocalValueResult returns requiresOffset, which Mantine now uses. daisyui reads a non-text value with readInstant(value) with a corrected comment, and utility-functions.md has the epoch/Date paragraph.

@heath-freenome heath-freenome left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, this round covers everything from my last review:

  • the UTC-midnight rule for format: 'date'
  • the 0–9999 year guard
  • reading an instant exactly in daisyui, with a test for the night clocks go back
  • the rewritten comment
  • the docs paragraph
  • sharing requiresOffset with Mantine

The code is nearly there. Two small requests and two optional nits are inline.

The PR description needs another pass too:

  • It still says every format except date-time/datetime gets local wall-clock time, which leaves out the format: 'date' UTC-midnight rule.
  • It says the daisyui DateTimeWidget "now reads only the getDateTimeLocalValue() result". That's no longer true, since it reads a number or Date as the instant it is.

Comment thread CHANGELOG-v7.md Resolved
@drakeo338

Copy link
Copy Markdown
Contributor Author

Done: the CHANGELOG bullet uses your text, the format: 'date' branch now gives undefined for years outside 0-9999 (with tests for years 10000 and -3), and Mantine passes localValue to offsetValueParser(). I kept the useMemo in Mantine's DateTimeInput, because without it preserve-manual-memoization fails lint on handleChange again.

@heath-freenome heath-freenome left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, the CHANGELOG, the year guard and its tests, and offsetValueParser(localValue) all look right. The useMemo reason makes sense too, so please keep it.

Two things outside the inline comments:

  • The size check fails. @rjsf/utils (without dependencies) is now 21.01 kB, over its 21 kB budget. Please bump own for @rjsf/utils to '22 kB' in .github/size-limit/.size-limit.js. The base was already at 20.88 kB, so this is the natural point to raise it.
  • The PR description still needs updating. It says every format except date-time/datetime gets local wall-clock time, which leaves out the format: 'date' UTC-midnight rule. It also says daisyui "reads only the getDateTimeLocalValue() result".

Inline:

  • You were right about the hour when clocks go back. That was my mistake, so I'm suggesting you revert that part.
  • One more gap: Mantine fields with a custom valueFormat.

@heath-freenome

Copy link
Copy Markdown
Member

@drakeo338 still a few comments awaiting responses

@heath-freenome heath-freenome left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, this round looks good. The daisyui revert, dropping the test, and the Mantine valueFormat fix with its test are exactly what I was after, and the code is ready from my side.

One thing left before I approve:

  • The PR description: it still says "every other format, including iso-date-time" gets local wall-clock time. That leaves out the format: 'date' rule, where an epoch or Date at UTC midnight comes back as the day it names. (The line about daisyui reading only the getDateTimeLocalValue() result is accurate again after the revert.)

Two optional nits, fine to skip:

  • The new Mantine test passes in any zone, so it covers the valueFormat fix. Pinning a zone west of UTC, such as America/Los_Angeles, would also make it catch a UTC-midnight day shift in Mantine.
  • Mantine now has its own change for non-string values, so a short bullet under ## @rjsf/mantine in CHANGELOG-v7.md wouldn't hurt, though the utils bullet arguably covers it.

I'll approve once the description is updated and the remaining build jobs pass.

@drakeo338

Copy link
Copy Markdown
Contributor Author

Updated the description with the format: 'date' rule, and added a short ## @rjsf/mantine CHANGELOG bullet for the valueFormat fix.

@heath-freenome

Copy link
Copy Markdown
Member

@drakeo338 Thanks for working with me to get this PR over the line

@heath-freenome
heath-freenome merged commit 9af3757 into rjsf-team:v7 Oct 4, 2026
6 checks passed
@heath-freenome heath-freenome mentioned this pull request Nov 13, 2026
Merged
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants