fix(gui): resolve date and date_range day loss in negative UTC offsets (#2879)#2881
Open
Marcelluxx wants to merge 1 commit into
Open
fix(gui): resolve date and date_range day loss in negative UTC offsets (#2879)#2881Marcelluxx wants to merge 1 commit into
Marcelluxx wants to merge 1 commit into
Conversation
- Avoid direct in-place mutation of Date objects by cloning them inside getTimeZonedDate - Avoid applying timezone offset adjustments to date-only pickers (withTime=false) - Parse date-only ISO strings (YYYY-MM-DD) as local midnight instead of UTC midnight in getDateTime - Add unit tests verifying robust local date-only parsing and formatting - Fix missing withTime prop in DateSelector.spec.tsx test
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.
What type of PR is this? (Check all that apply)
Description
This PR fixes a critical bug where
tgb.dateandtgb.date_rangewithwith_time=Falselose exactly one day every time a new date is selected if the browser is in a timezone with a negative UTC offset (e.g.,America/Los_Angeleswhich is UTC-0700).🔍 Root Cause
getDateTime(), date-only ISO strings (like"2025-06-06") were parsed usingnew Date(value). The JS standard specifies that date-only ISO strings should be parsed as UTC midnight. In a negative timezone, UTC midnight translates to the previous day in local time (e.g. June 5th 17:00:00), leading to a day-loss on initial rendering.getTimeZonedDate(), timezone adjustments directly mutated the Date object in-place (const newDate = d), polluting the React component state. Additionally, date-only values were being shifted by timezone offset hours, leading to cumulative day-loss on updates.🛠️ Proposed Changes
getTimeZonedDate()to clone the incoming date (const newDate = new Date(d)) to protect React state against side-effects.withTimeisfalseinsidegetTimeZonedDate(). Local hours and minutes are now cleanly set to local midnight (00:00), ensuring the local date components match exactly what the user selected.getDateTime()to detect date-only strings (matching^(\d{4})-(\d{2})-(\d{2})) and construct theDateobject using local date components (new Date(year, monthIndex, day)) instead of UTC midnight.withTime={true}prop to a test insideDateSelector.spec.tsxthat asserts time formatting.index.spec.tsvalidating robust date-only parsing, formatting, and clone/non-mutation behaviors.Related Tickets & Documents
How to reproduce the issue
America/New_YorkorAmerica/Los_Angeles).<tgb:date d="{date_var}" with_time="False"/>06/06/2025). The display will immediately slip back and show06/05/2025.Backporting
This change should be backported to:
Checklist
We encourage keeping the code coverage percentage at 80% or above.
If not, explain why: No E2E UI-level automation tests were added because the bug and its fix reside in core client-side parsing utility code, which is 100% covered and verified by the new unit tests in
index.spec.tsand component tests inDateSelector.spec.tsx.If not, explain why: The public API, properties, and configuration syntax remain unchanged; this is an internal logic fix.
If not, explain why: Standard internal bugfix; will be logged automatically by maintainers on merge.