Repository navigation
fix(webapps): validate SDK calendar dates - #3901
hauptmedia wants to merge 2 commits into
Conversation
|
Our agreement was not to add improvements or changes to the web apps, and the SDK for the forms is pretty niche. @kthoms wdyt? |
|
I am not against strengthening the datetime validation, but would expect to use a lib function for the check. |
|
Ok to merge for 2.3 @javahippie ? |
|
Yes, would see it as a 2.3 target. I share your opinion on a library for this check, rolling your own date-time logic seems not ideal to me |
|
@hauptmedia Could you please update? Ideally there is already some library in the dependencies that could be used, otherwise use a lightweight satisfying library. |
kthoms
left a comment
There was a problem hiding this comment.
Use library for datetime check
Delegate calendar and time-range checks to the existing Moment dependency while preserving the SDK date grammar and local conversion output. Extend boundary and timezone regression coverage.
|
Updated to use the existing Moment.js dependency instead of the custom Gregorian calendar and time-range checks. No additional package is needed.
The PR description now includes a 2.3 release-note entry explaining which previously accepted invalid inputs will be rejected. The existing 2.3.0 milestone is retained. |
|
|
I think the change mixed the old approach with a verification via moment.js. I'd try and parse the date with three allowed patterns in moment.js instead of keeping the regex as a separate step: var DATE_FORMATS = [
'YYYY-MM-DDTHH:mm:ss', 'YYYY-MM-DDTHH:mm:ss.',
'YYYY-MM-DDTHH:mm:ss.S', 'YYYY-MM-DDTHH:mm:ss.SS',
'YYYY-MM-DDTHH:mm:ss.SSS', 'YYYY-MM-DDTHH:mm:ss.SSSS',
];
moment.utc(dateToString(value), DATE_FORMATS, true).isValid(); |



Summary
SDK form date validation currently checks only the input's shape, accepting nonexistent dates such as
2023-02-29T12:34:56,2024-04-31T12:34:56, and invalid times such as2024-01-01T25:00:00. These inputs can also be returned byconvertToTypewithout an error.Use the existing Moment.js dependency to validate calendar and time fields via
moment.utc([...]).isValid(). Moment is already used in the SDK forms code; this adds no dependency or lockfile change. UTC field-array validation avoids host timezone/DST normalization and locale-sensitive string parsing, while conversion continues returning the original local value.Retain the SDK's input grammar: four-digit years, mandatory seconds, zero-to-four fractional digits, the legacy trailing decimal point, second 60, and
24:00:00only when all smaller fields are zero. A small compatibility adapter maps second 60 for validation and represents any nonzero fraction as a millisecond, preventing Moment from truncating.0001at end-of-day. Offset/Z strings remain unsupported. Calendar and time-range checks are delegated to Moment.The regression suite now contains 64 date cases, including early years, century leap-year rules, month/year boundaries, leap seconds, submillisecond end-of-day rejection, invalid Date objects, and UTC/New York/Kathmandu/Apia timezone behavior.
This is the SDK date-validation fix extracted from #3820, targeted for milestone 2.3.0. Its standard Mocha/Chai runner and
npm run test:sdkcommand are supplied by #3900; merge that test-harness PR first to run the regression through the standard command.Release note for 2.3
Embedded-form SDK Date fields now reject impossible calendar dates and out-of-range times instead of accepting strings solely because they match the date format. For example,
2023-02-29T12:34:56and2024-01-01T25:00:00are rejected, andconvertToType(value, 'Date')throws for such inputs. Applications supplying invalid date strings must correct them. Valid local date strings and the existing supported notation are preserved; timezone-offset andZsuffixes remain unsupported.Validation
dateTypeSpec.jsplus 11 existingtypeUtilSpec.jscases. Executed with the project's Moment/fast-xml-parser versions and fix(webapps): restore frontend test harnesses #3900's Mocha/Chai versions in an isolated dependency installation, without adding test infrastructure to this PR.git diff --checkpass.