Repository navigation
[feature] Add internal date-default hook for Moment Timezone - #6451
Merged
Merged
Conversation
Contributor
Author
|
Note, I made an exception to the "no new features" policy for this hook, because its sole purpose is to contribute towards a fix of a longstanding bug in moment-timezone. It adds no new actual user-facing features to either project. The remainder of the moment-timezone fix is in moment/moment-timezone#1161. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds an internal
moment._getDefaultDateParts(config, now, forWeek)hook that extensions can use to supply the year, month, and date for omitted calendar fields.This is needed by Moment Timezone so parsing inputs such as time-only strings can default to the current calendar date in the configured default timezone rather than the host system timezone.
The hook is intentionally private and is not included in the TypeScript declarations.
Behavior
Moment's default implementation preserves existing local and UTC behavior.
The implementation also:
moment.updateOffsetbehavior when calculating week defaults.moment.now()lazily and only once across format-array candidates.There should be no behavior change unless an extension overrides the private hook.
Related issue
Supports the Moment Timezone fix for moment/moment-timezone#1160.
Testing
Added coverage for:
updateOffsetintegration.DDDandDDDD.Full validation passed: 3,942 tests and 165,049 assertions, including lint, formatting, TypeScript, and build checks.