Repository navigation
fix(core/datetime-input): ignore quoted literals when splitting format #2907
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@siemens/ix': patch | ||
| --- | ||
|
|
||
| Fix `ix-datetime-input` splitting its `format` into date and time parts when a quoted literal contains time token letters (for example `dd.MM.yyyy 'um' HH:mm` or `LL/dd/yyyy 'at' hh:mm a`). Previously the literal was cut in half, so selecting a value in the picker could commit a wrong hour. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,8 +10,24 @@ export const LUXON_DEFAULT_DATE_ONLY_FORMAT = 'yyyy/LL/dd'; | |
| /** Used when a format string has no time tokens. */ | ||
| export const LUXON_DEFAULT_TIME_ONLY_FORMAT = 'HH:mm:ss'; | ||
|
|
||
| /** | ||
| * Index of the first time token in `format`, ignoring text inside single | ||
| * quotes, which Luxon treats as literal (e.g. `'at'`, `'um'`). | ||
| */ | ||
| function firstLuxonTimeTokenIndex(format: string): number { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This no longer merges. #2883 moved this file to Please rebase onto main and replay this change onto the new path. |
||
| return format.search(/[HhmsaSZ]/); | ||
| let inQuote = false; | ||
|
|
||
| for (let i = 0; i < format.length; i++) { | ||
| const char = format[i]; | ||
|
|
||
| if (char === "'") { | ||
| inQuote = !inQuote; | ||
| } else if (!inQuote && /[HhmsaSZ]/.test(char)) { | ||
| return i; | ||
| } | ||
| } | ||
|
|
||
| return -1; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -29,8 +45,18 @@ export function getLuxonDateOnlyFormatMask( | |
| } | ||
|
|
||
| let end = timeTokenIndex; | ||
| while (end > 0 && " \t'T".includes(format[end - 1])) { | ||
| end--; | ||
| while (end > 0) { | ||
| const char = format[end - 1]; | ||
|
|
||
| if (char === "'") { | ||
| // Drop the whole quoted literal that joins date and time, e.g. 'T' or 'at' | ||
| const openingQuote = format.lastIndexOf("'", end - 2); | ||
| end = openingQuote === -1 ? end - 1 : openingQuote; | ||
| } else if (' \tT'.includes(char)) { | ||
| end--; | ||
| } else { | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| const prefix = format.slice(0, end).trimEnd(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add
Fixes #2906to this summary so the issue closes when the changeset is released (.github/instructions/code-review.instructions.md).