fix/plugin(tz/utc) broken on dst change #3008
Open
JasonLiu-1214 wants to merge 2 commits intoiamkun:devfrom
Open
fix/plugin(tz/utc) broken on dst change #3008JasonLiu-1214 wants to merge 2 commits intoiamkun:devfrom
JasonLiu-1214 wants to merge 2 commits intoiamkun:devfrom
Conversation
added 2 commits
February 15, 2026 06:43
Problem:
During daylight saving time (DST) transitions, date normalization could produce incorrect results.
Example:
dayjs('2025-11-02T09:00:00Z').tz('utc').startOf('day').toISOString()
Unexpected output:
2025-11-01T23:00:00.000Z
Root cause:
Using new Date(target) relies on environment-dependent native Date parsing, which may shift values around DST boundaries.
Solution:
Replace new Date(target) with parseUSLocaleDate for deterministic string-based parsing
Avoid native Date parsing to prevent implicit timezone conversion
Ensure consistent startOf('day') calculation in UTC
Problem:
During daylight saving time (DST) transitions, timezone normalization could produce incorrect results after offset adjustments.
Example:
dayjs.tz('2012-03-11 02:59:59', 'America/New_York').format()
Expected output:
2012-03-11T03:59:59-04:00
Actual output:
2012-03-11T04:59:59-04:00
Root cause:
After applying timezone offset adjustments, DST transitions can change the effective offset.
The previous logic did not recalculate the offset after add(), causing an extra hour shift during DST boundaries.
Author
tz Issue ExplanationThe proto.tz = function (timezone = defaultTimezone, keepLocalTime) {
...
const target = date.toLocaleString('en-US', { timeZone: timezone })
const diff = Math.round((date - new Date(target)) / 1000 / 60)
...
}On 2025-11-02 01:00, when the transition from DST to standard time occurs: date UTC-8 target UTC-7
2025-11-02 00:00 2025-11-02 07:00
|---- -23h ~ +23h ----|
2025-11-02 01:00
|
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.
Problem
1. DST-related date normalization issue
During daylight saving time (DST) transitions, date normalization could produce incorrect results when using
startOf('day')in timezone conversions.Example:
Unexpected output:
Root cause:
new Date(target), which uses environment-dependent native parsing.2. DST transition offset recalculation issue in timezone plugin
During DST transitions, timezone normalization could produce incorrect results after offset adjustments.
Example:
Expected output:
Actual output:
Root cause:
add(), causing an extra one-hour shift around DST boundaries.Solution
1. Deterministic parsing for DST-safe normalization
new Date(target)withparseUSLocaleDateto avoid environment-dependent native parsing.startOf('day')behavior when normalizing dates in UTC.2. Recalculate offset after DST-sensitive adjustments
add()to account for DST boundary changes.Tests
Added new test cases covering DST edge scenarios:
startOf('day')in UTC.