Skip to content

Comments

fix: correct date display by preventing timezone conversion#2

Open
matiasmoya wants to merge 1 commit intomariohamann:mainfrom
matiasmoya:1-fix-timezone-offset
Open

fix: correct date display by preventing timezone conversion#2
matiasmoya wants to merge 1 commit intomariohamann:mainfrom
matiasmoya:1-fix-timezone-offset

Conversation

@matiasmoya
Copy link

Description

Fixes the date offset bug where activity graph tooltips (td title attribute) displayed dates one day before the actual activity data.

Closes #1

Problem

  • currentDate is created using Date.UTC(), which creates a UTC date.
  • The toLocaleDateString() method on line 143 was converting UTC dates to the user's local timezone, causing a date shift.

For example, if you're in a timezone behind UTC (like America/New_York, UTC-5), a UTC date of 2025-09-29 00:00:00 UTC becomes 2025-09-28 19:00:00 EST in local time, which then displays as 2025-09-28.

Solution

Added { timeZone: 'UTC' } option to toLocaleDateString() to ensure dates are formatted in UTC and match the activity data keys.

Changed

  • src/activity-graph-element.js line 143

Before

const text = `${currentDate.toLocaleDateString(lang)} – Activities: ${
    activityData[dateKey] || 0
}`;

After

const text = `${currentDate.toLocaleDateString(lang, { timeZone: 'UTC' })} – Activities: ${
    activityData[dateKey] || 0
}`;

Testing

Tested in GMT-3 timezone:

  • ✅ Dates now correctly match the activity data
  • ✅ No date shift occurs
  • ✅ Tooltip displays the correct date

Fixes #1

The toLocaleDateString() call was converting UTC dates to local timezone,
causing dates to display one day earlier in timezones behind UTC.

For example, if you're in a timezone behind UTC (like America/New_York, UTC-5),
a UTC date of 2025-09-29 00:00:00 UTC becomes 2025-09-28 19:00:00 EST in local time,
which then displays as 2025-09-28.

Added timeZone: 'UTC' option to preserve the correct date.
Copy link
Owner

@mariohamann mariohamann left a comment

Choose a reason for hiding this comment

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

Sorry, just saw your PR. Thanks for digging into it! Didn't have the time to try it myself, but raised a question.

Comment on lines +143 to +148
const text = `${currentDate.toLocaleString(lang, {
timeZone: 'UTC',
year: 'numeric',
month: '2-digit',
day: '2-digit'
})} – Activities: ${activityData[dateKey] || 0}`;
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
const text = `${currentDate.toLocaleString(lang, {
timeZone: 'UTC',
year: 'numeric',
month: '2-digit',
day: '2-digit'
})} Activities: ${activityData[dateKey] || 0}`;
const text = `${currentDate.toLocaleString(lang, {
timeZone: 'UTC'
})} Activities: ${activityData[dateKey] || 0}`;

Copy link
Owner

Choose a reason for hiding this comment

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

Would this work as well?

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.

Graph dates off by one day due to timezone conversion bug

2 participants