Skip to content

fix(webapps): validate SDK calendar dates - #3901

Open
hauptmedia wants to merge 2 commits into
mainfrom
codex/sdk-date-validation
Open

hauptmedia wants to merge 2 commits into
mainfrom
codex/sdk-date-validation

Conversation

@hauptmedia

@hauptmedia hauptmedia commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator

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 as 2024-01-01T25:00:00. These inputs can also be returned by convertToType without 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:00 only 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 .0001 at 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:sdk command 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:56 and 2024-01-01T25:00:00 are rejected, and convertToType(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 and Z suffixes remain unsupported.

Validation

  • 75 tests passed: all 64 cases in dateTypeSpec.js plus 11 existing typeUtilSpec.js cases. 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.
  • Differential check of the updated production function against the previous PR implementation: 1,184,810 cases with no differences, including a 400-year calendar cycle, time-field boundaries, fractions, and conversion outputs.
  • Targeted ESLint, Prettier and git diff --check pass.
  • The repository cleanup script ran non-recursively on the root POM. It reported existing OpenRewrite recipe-validation errors (invalid style recipe and unavailable/uninitialized recipes); the cleanup pipeline is not claimed as fully passing.
  • Full frontend/browser suites were not rerun for this focused validation change.

@github-actions github-actions Bot added lang:javascript Pull requests that update Javascript code scope:webapp Changes affecting the legacy webapps. labels Oct 22, 2026
@javahippie

Copy link
Copy Markdown
Contributor

Our agreement was not to add improvements or changes to the web apps, and the SDK for the forms is pretty niche.

@kthoms wdyt?

@kthoms

kthoms commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

I am not against strengthening the datetime validation, but would expect to use a lib function for the check.
I think this behavioral change is acceptable. Maybe worth documenting in the Release Notes.

@kthoms

kthoms commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

Ok to merge for 2.3 @javahippie ?

@javahippie

Copy link
Copy Markdown
Contributor

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

@kthoms

kthoms commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

@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 kthoms left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Use library for datetime check

@kthoms kthoms added this to the 2.3.0 milestone Oct 23, 2026
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.
@hauptmedia

Copy link
Copy Markdown
Collaborator Author

Updated to use the existing Moment.js dependency instead of the custom Gregorian calendar and time-range checks. No additional package is needed.

moment.utc([...]).isValid() validates the fields without host timezone/DST normalization. The compatibility adapter preserves the SDK's existing leap-second and fractional-second notation, while conversion still returns the original local value. Added boundary and timezone regressions: all 75 date/type-util tests pass, as do targeted ESLint and Prettier checks.

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.

@sonarqubecloud

Copy link
Copy Markdown

@javahippie

Copy link
Copy Markdown
Contributor

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();

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lang:javascript Pull requests that update Javascript code scope:webapp Changes affecting the legacy webapps.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants