Fix 12-hour time format issue in graphs by implementing custom 24-hour formatter#254
Fix 12-hour time format issue in graphs by implementing custom 24-hour formatter#254
Conversation
…r formatter Co-authored-by: abh <16861+abh@users.noreply.github.com>
Co-authored-by: abh <16861+abh@users.noreply.github.com>
There was a problem hiding this comment.
Pull Request Overview
This PR implements a custom 24-hour time formatter to resolve inconsistent time displays in the graphs by replacing D3.js’s default formatter in both server and zone visualizations.
- Improved time formatting logic using a custom formatter for consistent 24-hour display
- Updates made separately in graphs.server.js and graphs.zone.js to address the issue
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| docs/shared/static/js/graphs.zone.js | Added custom24HourFormatter and replaced tickFormat() call |
| docs/shared/static/js/graphs.server.js | Added custom24HourFormatter and replaced tickFormat() call |
| .attr("y1", 0) | ||
| .attr("y2", h); | ||
|
|
||
| // Custom 24-hour time formatter to avoid 12-hour format in minute displays |
There was a problem hiding this comment.
The custom24HourFormatter function is duplicated in multiple files. Consider extracting it to a shared utility module to reduce redundancy and simplify future maintenance.
| .attr("y1", 0) | ||
| .attr("y2", h); | ||
|
|
||
| // Custom 24-hour time formatter to avoid 12-hour format in minute displays |
There was a problem hiding this comment.
The custom24HourFormatter function appears to be identically implemented here as in graphs.zone.js. Extracting this common logic to a shared module could improve maintainability and consistency.
b215a04 to
1ab7f20
Compare
|
@copilot please rebase on main branch |
Done. Merged the main branch into this PR branch (commit |
This PR fixes the confusing time display issue in graphs where minutes were shown in 12-hour format without AM/PM indicators, while hours were correctly displayed in 24-hour format.
Problem
The issue occurred when D3.js default
tickFormat()method mixed 12-hour and 24-hour time formats, creating confusing sequences like:Solution
Implemented a custom 24-hour time formatter that replaces D3's default
tickFormat()inclient/src/charts/zone-chart.ts:server-chart.tsalready used explicitd3.utcFormat('%H:%M')specifiers via itscreateDateFormatterfunction.Result
Time displays are now consistent with 24-hour format throughout:
Changes
client/src/charts/zone-chart.ts— Addedformat24HourDate()helper and replacedxScale.tickFormat()call with itTesting
🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.