Skip to content

Fix #274: Correct timezone parsing in dashboard statistics chart#275

Closed
ding113 wants to merge 1 commit intodevfrom
fix/issue-274-timezone-display
Closed

Fix #274: Correct timezone parsing in dashboard statistics chart#275
ding113 wants to merge 1 commit intodevfrom
fix/issue-274-timezone-display

Conversation

@ding113
Copy link
Owner

@ding113 ding113 commented Dec 5, 2025

Summary

Fixes the timezone display issue in the dashboard statistics chart reported in #274.

Root Cause

The formatDate and formatTooltipDate functions in chart.tsx used new Date(dateStr) to parse date strings. When the backend returns date-only strings like "2025-12-06", JavaScript's Date constructor interprets them as UTC midnight rather than local midnight. This causes a timezone offset when displaying dates to users in non-UTC timezones (e.g., UTC+8).

Solution

Added a parseLocalDate helper function that manually parses date strings into local Date objects by extracting year, month, day, and time components. This ensures dates are interpreted as local time regardless of the input format.

Changes

  • Added parseLocalDate() helper function that correctly parses date strings as local time
  • Updated formatDate() to use parseLocalDate() instead of new Date()
  • Updated formatTooltipDate() to use parseLocalDate() instead of new Date()

Test Plan

  • Verify dashboard chart displays correct dates in UTC+8 timezone
  • Verify tooltip shows correct dates/times
  • Test with different time ranges (today, 7 days, 30 days, this month)
  • Test with hourly resolution data

Closes #274

🤖 Generated with Claude Code



The dashboard chart was incorrectly parsing date strings using `new Date()`,
which treats date-only strings (e.g., "2025-12-06") as UTC midnight instead
of local midnight. This caused dates to display incorrectly for users in
non-UTC timezones.

Added `parseLocalDate` helper that manually parses date strings as local
time, fixing the timezone offset issue in both the chart axis labels and
tooltip displays.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @ding113, 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!

此拉取请求旨在解决仪表盘统计图表中存在的时区显示错误。通过引入一个自定义的日期解析函数 parseLocalDate,确保了日期字符串始终被解释为本地时间,从而消除了 new Date() 在处理纯日期字符串时可能导致的 UTC 偏移问题,为不同时区的用户提供了准确的日期显示。

Highlights

  • 时区解析修复: 解决了仪表盘统计图表中日期显示因时区解析不当而出现偏差的问题。
  • 新增本地日期解析函数: 引入了一个名为 parseLocalDate 的辅助函数,用于将日期字符串手动解析为本地 Date 对象,以避免 new Date() 对纯日期字符串的 UTC 解析行为。
  • 更新日期格式化逻辑: 更新了 formatDateformatTooltipDate 函数,使其内部使用新添加的 parseLocalDate 函数来确保日期始终以本地时间正确显示。
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.

@ding113 ding113 added the size/XS Extra Small PR (< 50 lines) label Dec 5, 2025
Copy link
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 correctly addresses a timezone parsing issue where date-only strings were being interpreted as UTC. The introduction of the parseLocalDate helper function to explicitly handle date strings as local time is the right approach. The changes in formatDate and formatTooltipDate correctly apply this new helper.

My review includes a suggestion to make the new parseLocalDate function more robust by using a regular expression for parsing. This will make it less prone to errors with malformed or unexpected date string formats. Overall, this is a good fix for the reported bug.

Comment on lines +49 to +54
function parseLocalDate(dateStr: string): Date {
const normalized = dateStr.replace("T", " ").split(" ");
const [year, month, day] = normalized[0].split("-").map(Number);
const timePart = normalized[1]?.split(":").map(Number) || [0, 0, 0];
return new Date(year, month - 1, day, timePart[0] || 0, timePart[1] || 0, timePart[2] || 0);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The current implementation for parseLocalDate is a good solution for the timezone problem. However, it relies on split which can be fragile if the date string format varies slightly or is malformed.

I suggest using a regular expression to parse the date string, which is more robust and explicit about the expected format. This revised version ensures that only strings matching the YYYY-MM-DD format (with an optional time part) are parsed this way, falling back to the default new Date() constructor for any other format. This makes the function more predictable.

function parseLocalDate(dateStr: string): Date {
  const match = dateStr.match(/^(\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2}):(\d{2}))?/);
  if (!match) {
    return new Date(dateStr);
  }
  const [, y, m, d, h, i, s] = match;
  return new Date(Number(y), Number(m) - 1, Number(d), Number(h) || 0, Number(i) || 0, Number(s) || 0);
}

@ding113 ding113 added the bug Something isn't working label Dec 5, 2025
Copy link
Owner Author

@ding113 ding113 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 Summary

No significant issues identified in this PR. The parseLocalDate helper function correctly addresses the UTC vs local time parsing issue by manually constructing Date objects from parsed components.

PR Size: XS

  • Lines changed: 21 (18 additions, 3 deletions)
  • Files changed: 1

Review Coverage

  • Code quality and correctness - Clean
  • Security (OWASP Top 10) - Clean
  • PR size assessment - XS
  • Dependency changes - N/A (no package changes)
  • Documentation changes - N/A (no docs changes)

Automated review by Claude AI

Copy link
Owner Author

@ding113 ding113 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 Summary

No significant issues identified in this PR. The parseLocalDate helper function correctly addresses the UTC vs local time parsing issue by manually constructing Date objects from parsed components.

PR Size: XS

  • Lines changed: 21 (18 additions, 3 deletions)
  • Files changed: 1

Review Coverage

  • Code quality and correctness - Clean
  • Security (OWASP Top 10) - Clean
  • PR size assessment - XS
  • Dependency changes - N/A (no package changes)
  • Documentation changes - N/A (no docs changes)

Automated review by Claude AI

@ding113 ding113 closed this Dec 6, 2025
@github-project-automation github-project-automation bot moved this from Backlog to Done in Claude Code Hub Roadmap Dec 6, 2025
@ding113 ding113 deleted the fix/issue-274-timezone-display branch December 11, 2025 10:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working size/XS Extra Small PR (< 50 lines)

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant

Comments