fix: mixed-case "MS" unit resolves to millisecond instead of crashing get() - #3184
Open
koding88 wants to merge 1 commit into
Open
fix: mixed-case "MS" unit resolves to millisecond instead of crashing get()#3184koding88 wants to merge 1 commit into
koding88 wants to merge 1 commit into
Conversation
prettyUnit consulted the special map before lowercasing, then
stripped a trailing 's', so 'MS'/'Ms'/'mS' resolved to the string
'm'. Consequences while every other unit was case-insensitive:
- get('MS') threw TypeError (this.m is not a function)
- set('MS', n) was a silent no-op
- startOf/endOf('MS') were clone-only no-ops
Look up the special map again after lowercasing so mixed-case ms
behaves exactly like 'ms'.
There was a problem hiding this comment.
🟢 Approval recommended
The change is narrowly scoped to unit normalization, preserves existing mappings by checking exact keys first, and is covered by targeted unit and integration tests.
Pull request overview
Fixes prettyUnit so mixed-case millisecond units ("MS", "Ms", "mS") resolve to "millisecond" consistently (as documented) instead of incorrectly collapsing to "m" (minute) and causing crashes/no-ops in APIs like get, set, and startOf.
Changes:
- Update
prettyUnitto re-check the special-unit map after lowercasing the input (fixing the mixed-case"ms"family). - Add unit tests covering mixed-case
msvariants inPrettyUnit. - Add integration-style tests verifying
get('MS'),set('MS'|'Ms', n), andstartOf('MS')behave like their lowercase equivalents.
File summaries
| File | Description |
|---|---|
| src/utils.js | Adjusts prettyUnit resolution order to correctly handle mixed-case millisecond units. |
| test/utils.test.js | Adds direct prettyUnit coverage for "MS", "Ms", and "mS". |
| test/get-set.test.js | Adds coverage ensuring get/set/startOf work correctly with mixed-case millisecond units. |
Review details
- Files reviewed: 3/3 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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
Units are documented as case-insensitive, but mixed-case forms of
msbroke in three different ways:While every other unit resolves correctly in any casing (
'HOUR','Day','MONTH'…).Root cause
prettyUnit(src/utils.js) consulted the special map before lowercasing and then stripped a trailings:get('MS')then calledthis['m'](), which does not exist on the prototype (the minute getter is registered under the full name'minute') and threw.Fix
Look up the special map again after lowercasing:
Exact-key mappings are still consulted first, so every existing resolution is unchanged (
'D'→'date','m'→'minute','minutes'→'minute', …). Only the broken mixed-casemsfamily changes behavior — to match its lowercase form, as the docs already promise.Tests
PrettyUnit:MS/Ms/mS→millisecondget('MS'),set('MS'|'Ms', n)work;startOf('MS')is identical tostartOf('ms')Checklist
npm run lintcleannpm testgreen — 94 suites / 797 tests, line coverage unchanged at 100%