-
-
Notifications
You must be signed in to change notification settings - Fork 158
date shift issue fix #855
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
date shift issue fix #855
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -345,7 +345,11 @@ export const PreferencesProvider: React.FC<{ children: React.ReactNode }> = ({ | |
|
|
||
| if (typeof date === 'string') { | ||
| // If it's a full ISO string with time (e.g. 2026-02-16T...), keep it as is for parseISO | ||
| if (date.match(/^\d{4}-\d{2}-\d{2}$/) || date.includes('T00:00:00')) { | ||
| if ( | ||
| date.match(/^\d{4}-\d{2}-\d{2}$/) || | ||
| date.includes('T00:00:00') || | ||
| (date.endsWith('Z') && date.includes('T00:00')) | ||
| ) { | ||
| // IMPORTANT: Treat YYYY-MM-DD as a literal local date to avoid UTC-to-Local shifting. | ||
| const datePart = date.split('T')[0]; | ||
| if (datePart) { | ||
|
|
@@ -389,6 +393,22 @@ export const PreferencesProvider: React.FC<{ children: React.ReactNode }> = ({ | |
| loggingLevel, | ||
| `PreferencesProvider: Parsing date string "${dateString}".` | ||
| ); | ||
|
|
||
| // Handle literal date strings (YYYY-MM-DD or DB DATE format) to prevent shifting | ||
| if ( | ||
| dateString.match(/^\d{4}-\d{2}-\d{2}$/) || | ||
| dateString.includes('T00:00:00') || | ||
| (dateString.endsWith('Z') && dateString.includes('T00:00')) | ||
| ) { | ||
| const datePart = dateString.split('T')[0]; | ||
| if (datePart) { | ||
| const [year, month, day] = datePart.split('-').map(Number); | ||
| if (year && month && day) { | ||
| return new Date(year, month - 1, day); | ||
| } | ||
| } | ||
| } | ||
|
Comment on lines
+397
to
+410
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This block of logic for handling literal date strings is nearly identical to the logic in the I've left a comment on the other instance with a suggestion for a more robust implementation. It would be best to extract that improved logic into a shared helper function and call it from both |
||
|
|
||
| const parsedDate = parseISO(dateString); | ||
| return startOfDay(parsedDate); | ||
| }, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The condition
date.includes('T00:00')is too broad and can lead to bugs. For example, a date string like'2023-01-01T00:00:30Z'would match, causing the time information to be incorrectly truncated. This can lead to subtle date-shifting issues.The logic can be simplified and made more robust by checking if the time part of the string contains any non-zero digits. This correctly identifies true midnight timestamps while ignoring others.