fix(timezone): preserve timezone context when adding calendar units#2961
Open
SHARMA1525 wants to merge 1 commit intoiamkun:devfrom
Open
fix(timezone): preserve timezone context when adding calendar units#2961SHARMA1525 wants to merge 1 commit intoiamkun:devfrom
SHARMA1525 wants to merge 1 commit intoiamkun:devfrom
Conversation
Fix issue where adding days/weeks/months/years to timezone-aware dayjs objects
did not preserve timezone context correctly, causing incorrect valueOf() results
when converting back to timezone.
The fix overrides the add() method for timezone-aware objects to:
1. Format the date in timezone context
2. Add calendar units without timezone conversion
3. Convert back to timezone with keepLocalTime=true
This ensures all three approaches produce identical results:
- dayjs.tz(time, tz).add(1, 'day')
- dayjs.tz(dayjs.tz(time, tz).add(1, 'day').valueOf(), tz)
- dayjs.tz(dayjs.tz(time, tz).add(1, 'day').startOf('millisecond').valueOf(), tz)
Fixes issue where valueOf() and format() results were inconsistent after
adding calendar units to timezone-aware objects.
|
|
Author
|
I’ve raised a new PR that implements the suggested fix by patching the private init() function to recompute the timezone offset. This ensures DST offsets remain consistent across all methods (.add(), .set(), .startOf(), etc.), not just .add(). All test suites (93/93) pass successfully. Please take a look when you get a chance thank you again for your guidance! |
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.
Fix issue where adding days/weeks/months/years to timezone-aware dayjs objects did not preserve timezone context correctly, causing incorrect valueOf() results when converting back to timezone.
The fix overrides the add() method for timezone-aware objects to:
This ensures all three approaches produce identical results:
Fixes issue where valueOf() and format() results were inconsistent after adding calendar units to timezone-aware objects.
Linked Issue
#2957