date shift issue fix#855
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a critical date shifting issue in the frontend by refining how date strings are parsed and interpreted. The changes ensure that dates intended to be displayed as local dates, particularly those without specific time components or with zeroed-out time in UTC, are correctly rendered without being affected by timezone conversions, thereby preventing off-by-one day errors in the user interface. Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request addresses a date shifting issue by forcing certain date strings to be treated as local dates. The changes are applied in formatDateInUserTimezone and parseDateInUserTimezone.
My review focuses on two main points:
- Robustness: The new condition for identifying literal dates is a bit too broad and could cause bugs by incorrectly truncating time information from date-time strings that are not exactly at midnight. I've suggested a more robust implementation.
- Maintainability: The logic for handling these literal dates has been duplicated in two functions. I've recommended extracting this logic into a shared helper function to avoid code duplication and improve maintainability.
| if ( | ||
| date.match(/^\d{4}-\d{2}-\d{2}$/) || | ||
| date.includes('T00:00:00') || | ||
| (date.endsWith('Z') && date.includes('T00:00')) | ||
| ) { |
There was a problem hiding this comment.
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.
if (
date.match(/^\d{4}-\d{2}-\d{2}$/) ||
(date.includes('T') && !/[1-9]/.test(date.substring(date.indexOf('T') + 1)))
) {
| // 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); | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
This block of logic for handling literal date strings is nearly identical to the logic in the formatDateInUserTimezone function. This duplication can make the code harder to maintain and can lead to inconsistencies if one instance is updated but the other is not.
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 formatDateInUserTimezone and parseDateInUserTimezone to avoid duplication.
Tip
Help us review and merge your PR faster!
Please ensure you have completed the Checklist below.
For Frontend changes, please run
pnpm run validateto check for any errors.PRs that include tests and clear screenshots are highly preferred!
Description
Provide a brief summary of your changes.
Forced entry_date to show that as actual date in frontend to avoid date shift issues.
Related Issue
PR type [x] Issue [ ] New Feature [ ] Documentation
Linked Issue: #
Checklist
Please check all that apply:
pnpm run validate(especially for Frontend).en) translation file (if applicable).rls_policies.sqlfor any new user-specific tables.Screenshots (if applicable)
Before
[Insert screenshot/GIF here]
After
[Insert screenshot/GIF here]