Skip to content

date shift issue fix#855

Merged
CodeWithCJ merged 1 commit intomainfrom
dev
Mar 7, 2026
Merged

date shift issue fix#855
CodeWithCJ merged 1 commit intomainfrom
dev

Conversation

@CodeWithCJ
Copy link
Copy Markdown
Owner

Tip

Help us review and merge your PR faster!
Please ensure you have completed the Checklist below.
For Frontend changes, please run pnpm run validate to 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:

  • [MANDATORY for new feature] Alignment: I have raised a GitHub issue and it was reviewed/approved by maintainers
  • Tests: I have included automated tests for my changes.
  • [MANDATORY for UI changes] Screenshots: I have attached "Before" vs "After" screenshots below.
  • [MANDATORY for Frontend changes] Quality: I have run pnpm run validate (especially for Frontend).
  • Translations: I have only updated the English (en) translation file (if applicable).
  • Architecture: My code follows the existing architecture standards.
  • Database Security: I have updated rls_policies.sql for any new user-specific tables.
  • [MANDATORY - ALL] Integrity & License: I certify this is my own work, free of malicious code(phishing, malware, etc.) and I agree to the License terms.

Screenshots (if applicable)

Before

[Insert screenshot/GIF here]

After

[Insert screenshot/GIF here]

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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

  • Date Parsing Logic Enhancement: Enhanced the date parsing logic within PreferencesContext.tsx to correctly identify and handle date strings that represent literal local dates, specifically adding support for T00:00Z UTC timestamps with zeroed-out time, alongside existing YYYY-MM-DD and T00:00:00 patterns.
  • Explicit Local Date Construction: Implemented a new mechanism in the parseDateString function to explicitly construct Date objects from the year, month, and day components of specific date string formats. This ensures these dates are interpreted as local dates, bypassing parseISO for these cases to prevent unintended timezone shifts and off-by-one day errors.
Changelog
  • SparkyFitnessFrontend/src/contexts/PreferencesContext.tsx
    • Updated the conditional logic for identifying date strings that should be treated as literal local dates, adding support for T00:00Z patterns.
    • Introduced a new block in the parseDateString function to explicitly create Date objects from the year, month, and day components of specific date string formats, bypassing parseISO for these cases to avoid timezone shifts.
Activity
  • No human activity has been recorded for this pull request yet.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. 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.
  2. 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.

Comment on lines +348 to +352
if (
date.match(/^\d{4}-\d{2}-\d{2}$/) ||
date.includes('T00:00:00') ||
(date.endsWith('Z') && date.includes('T00:00'))
) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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)))
        ) {

Comment on lines +397 to +410
// 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);
}
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

@CodeWithCJ CodeWithCJ merged commit 38877bb into main Mar 7, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant