Skip to content

feat: Custom dayjs.parse() - #8328

Merged
bastianallgeier merged 2 commits into
v6/developfrom
v6/fix/dayjs-5-pattern-parse
Aug 3, 2026
Merged

feat: Custom dayjs.parse()#8328
bastianallgeier merged 2 commits into
v6/developfrom
v6/fix/dayjs-5-pattern-parse

Conversation

@distantnative

@distantnative distantnative commented Jul 26, 2026

Copy link
Copy Markdown
Member

Description

I think this one is hard to read the code to review. Probably better to just test it out via the lab example. Trying to explain the changed approach:

dayjs.interpret() used to guess what a user typed by throwing the input at a hardcoded list of ~70 format strings and taking the first that stuck. Often rather faulty as the number of long-around bug reports shows.

This PR introduces dayjs.parse() that replaces the dayjs core plugin customParseFormat and our previous dayjs.interpret(). It follows the following path:

  1. Match the pattern first: We have the display format pattern usually. And it's not unlikely the user will type something in that follows that pattern somewhat. So the input is split into tokens and matched positionally against the display pattern's parts. Neither the separators nor the number widths have to match exactly (e.g. a DD.MM.YYYY pattern still reads 2/3/24, 02.03.2024 and even 02032024), but it has to offer something sensible for all parts of the display pattern to be used.
  2. If that fails, then guess, but still informed by the pattern. Anything the pattern can't read exactly (partial input, another unit order) falls back to a small list of unit orders. dayjs.interpret() threw a long list at it, often faulty. But even when guessing, the display pattern should inform our guesses about which order to prioritize etc. So we test a list of guesses, but only guesses that use units the pattern also shows. And the ones agreeing with the pattern's order go first. strict: true skips this step entirely.

Because both iso() and parse() now build datetimes explicitly, the customParseFormat dayjs plugin is no longer needed.

DateInput still calls the deprecated interpret() without a pattern. Wiring the inputs up to parse() and their display pattern is happening in: #8322

Merge first

Changelog

✨ Enhancements

  • New $library.dayjs.parse(input, { pattern, strict, type }): parses what a user types against a display pattern to create a date time object.
  • Date field: Localized month names are recognized in English, including abbreviations. (and with feat: Locale support for dayjs #8327 also in the current Panel UI locale)

☠️ Deprecated

  • $library.dayjs.interpret() is deprecated. Use $library.dayjs.parse() instead.

For review team

@distantnative distantnative self-assigned this Jul 26, 2026
@distantnative
distantnative force-pushed the v6/fix/dayjs-3-strict-iso branch from ffdaa09 to 925e2c7 Compare July 26, 2026 13:28
@distantnative
distantnative force-pushed the v6/fix/dayjs-5-pattern-parse branch 10 times, most recently from 136f218 to edf06c5 Compare July 26, 2026 17:03
@distantnative distantnative changed the title feat: dayjs.pattern().read() feat: Custom dayjs.parse() Jul 26, 2026
@distantnative
distantnative force-pushed the v6/fix/dayjs-5-pattern-parse branch 3 times, most recently from 099e8ee to 8000ca5 Compare July 26, 2026 19:19
@distantnative
distantnative force-pushed the v6/fix/dayjs-3-strict-iso branch from be9b50f to dfdf683 Compare July 27, 2026 14:07
@distantnative
distantnative force-pushed the v6/fix/dayjs-5-pattern-parse branch from 8000ca5 to 5de2df2 Compare July 27, 2026 14:10
@distantnative distantnative added this to the 6.0.0-alpha.4 milestone Jul 27, 2026
Base automatically changed from v6/fix/dayjs-3-strict-iso to v6/develop July 29, 2026 08:22
@distantnative
distantnative marked this pull request as ready for review July 29, 2026 08:27
@distantnative
distantnative force-pushed the v6/fix/dayjs-5-pattern-parse branch from 5de2df2 to 418701c Compare July 29, 2026 08:29
@distantnative
distantnative force-pushed the v6/fix/dayjs-5-pattern-parse branch from 418701c to f9a445e Compare August 2, 2026 19:17
@bastianallgeier

Copy link
Copy Markdown
Member

I only quickly started to test the lab and wanted to change the format. But when I try, I immediately run into an error:

TypeError: can't access property "matchAll", this.source is undefined

Am I not supposed to change the format or is this an issue?

@distantnative

Copy link
Copy Markdown
Member Author

@bastianallgeier sorry seems at the end when cleaning up I renamed one string in the lab example wrongly.

@bastianallgeier
bastianallgeier self-requested a review August 3, 2026 15:46

@bastianallgeier bastianallgeier 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.

I've tested the pattern and parse tabs in the lab and it works really great.

@bastianallgeier
bastianallgeier merged commit bb046c8 into v6/develop Aug 3, 2026
3 checks passed
@bastianallgeier
bastianallgeier deleted the v6/fix/dayjs-5-pattern-parse branch August 3, 2026 15:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants