Repository navigation
Fix time zone edge cases, addMonths, and isSameDay; match numeral-script literal digits - #157
Merged
Merged
Conversation
Drop the @typescript-eslint/no-extraneous-class override and the prefer-promise-reject-errors and @stylistic/padding-line-between-statements rules, and the Vitest fsModuleCache and isolate options, leaving include as the only test setting.
Give each type bundle two outputs, the second renaming to .d.cts and rewriting the default export to export =, instead of a second config per entry, and drop the esbuild minify: false option, which is its default. Extend the build spec to the timezone modules' CJS interop and .d.cts output.
Test the zone name directly in the UTC branch of addDays, cache every recognized zone in getDateTimeFormat, reuse one global RegExp per numeral system for decode, check for a leading bracket before matching a literal in format and Duration, state the hour precedence of parse as one condition, and drop the Math.round that the whole-week difference in getISOWeek never needed.
With a time zone, a year before 1 CE lost its sign (format printed 6 for -5 with a garbled offset, and parsing January 1, 0001 in Tokyo gave a date in year -1), addYears threw on reaching year 0, and dates at the ends of the Date range gave a NaN offset, a garbled date, or Invalid Date. fromParts now passes Date.UTC() only the month within a 400-year cycle and adds the rest as days, dtfToParts moves a time outside 1600-2399 by whole 400-year cycles before formatToParts and restores the year, getTimezoneOffset searches any local time within a day of the Date range, and format detects an Invalid Date from the time instead of the year.
With a time zone, a fractional month moved the day before it was clamped, so 1.5 months after January 31 gave March 31 instead of February 28; in local time, a month that rolled over into a DST gap kept the gap's hour shift after stepping back with setDate(0). Compute the last day of the truncated target month first and set the month and day together in local time, UTC, and a time zone alike, using a 400-year cycle so the lookup also holds for years 0-99, before 1 CE, and at the ends of the Date range.
With a numeral system other than latn, a digit in literal text, bracketed or not, now matches the same digit in either Latin or the numeral system's script, so parse() reads back what format() writes for a pattern such as '[Q٣] YYYY'. preparse() decodes the input once up front, so _index and _length count positions in the decoded string, and an empty pair of brackets matches as an empty literal.
isSameDay compared toDateString() results, which are both 'Invalid Date' for two Invalid Dates, so it returned true. It now returns false whenever either date is invalid. Document the change in the API reference, the migration guide, and the migration skill.
Move the format and parse cases repeated in every locale spec into tests/locales/helper.ts, so each spec lists only its locale's strings and calls testLocale.
Name each timezone test after the module's path under src/timezones/ and assert that zone_name equals it, instead of only checking that it is a string.
…econds The S tokens of the microsecond and nanosecond plugins set the milliseconds and drop the extra digits, reading shorter input as if it had leading zeros, while the f and F tokens only skip their digits; the docs said every token was read and discarded. Correct the plugin guide and the skill references, and cover the shorter-input case in the plugin specs.
List Firefox 84+ and Safari 14.1+ as the minimum browsers and TypeScript 4.7+ as the minimum for the package's exports-based types, note that moduleResolution bundler needs TypeScript 5.0, and show the local mean time offset (GMT-0752) that Date prints for January 1, 0001 in Los Angeles.
Replace relative links such as ./format and ../plugins with /date-and-time/<route> paths in lowercase, which resolve under the site base from every page.
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
Release 4.9.0: fixes for dates at the edges of the calendar with a time zone,
addMonthsday clamping, andisSameDaywith Invalid Dates; numeral-script digits in pattern literals; internal refactors and a documentation pass.Feature
latn, a digit in literal text (bracketed or not) matches the same digit in Latin or that system's script, soparse()reads back whatformat()writes for patterns such as'[Q٣] YYYY'.preparse()positions (_index,_length) count the decoded string, and[]matches as an empty literalFixes
formatprinted6for-5),addYearsno longer throws on reaching year 0, and dates at the ends of the Date range no longer give a NaN offset, a garbled date, or Invalid Date.fromPartsanddtfToPartswork through 400-year cyclesfalsewhen either date is invalid; two Invalid Dates used to givetrue. Documented in the API reference, the migration guide, and the migration skillRefactors
RegExpper numeral system; skip the literal regex for tokens without a leading bracket informatandDuration; simplify theaddDaysUTC branch, theparsehour precedence, thegetDateTimeFormatcache, andgetISOWeekBuild / tooling
.d.tsand.d.ctsfrom one Rollup pass per entry; the build spec now covers the timezone modules' CJS interop and.d.ctsTests
format,parse,addDays,addYears,addMonths; numeral-script literals; shorter input to the microsecond/nanosecondStokens;isSameDaywith Invalid Datestests/locales/helper.ts; timezone tests checkzone_nameagainst the module pathDocs
Stokens set milliseconds (they were documented as read and discarded); skill references updated to matchbundlerneeds 5.0), and the LMT offset in aparseoutput/date-and-time/<route>pathsTest plan
npm run lint,npm testpassnpm run build && npx vitest run tests/buildpassestsc, ESLint, and Vitest on its own