fix(timeline): localize chart date labels#825
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #825 +/- ##
==========================================
+ Coverage 31.01% 31.32% +0.30%
==========================================
Files 34 34
Lines 1996 2005 +9
Branches 354 354
==========================================
+ Hits 619 628 +9
Misses 1356 1356
Partials 21 21 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Greptile SummaryThis PR removes hardcoded English weekday and month labels from
Confidence Score: 5/5Safe to merge; changes are confined to label formatting logic and introduce no data-path or behavioral regressions. All chart-label paths that previously used hardcoded English strings now delegate to Intl.DateTimeFormat with undefined locale (browser default), which is the correct approach. The weekly branch correctly anchors dates to local noon before day arithmetic. No existing logic is removed or altered beyond the label-generation step. No files require special attention. Important Files Changed
Reviews (2): Last reviewed commit: "fix(timeline): remove unsafe date label ..." | Re-trigger Greptile |
| function normalize_date(dateParam: Date | string) { | ||
| return dateParam instanceof Date ? new Date(dateParam.getTime()) : new Date(dateParam); | ||
| } |
There was a problem hiding this comment.
Date-only strings silently shift to wrong day in non-UTC timezones
new Date("2023-03-12") (ISO 8601 date-only) is parsed as UTC midnight per spec. When Intl.DateTimeFormat later formats that Date in the user's local timezone — say UTC-5 — it sees March 11 at 19:00 and renders Saturday instead of Sunday. Any caller who passes a date string like timeperiod_start directly to format_weekday_short or format_month_day will get the wrong label in any non-UTC timezone. The current Vue callers all pass Date objects with the time pre-set to local noon, so they are unaffected — but the exported API silently creates this footgun. Consider documenting that string inputs with date-only format are unsafe, or restricting the parameter type to Date.
| export function format_month_day(dateParam: Date | string, locale?: string | string[]) { | ||
| return new Intl.DateTimeFormat(locale, { day: 'numeric' }).format(normalize_date(dateParam)); | ||
| } |
There was a problem hiding this comment.
Misleading function name — only formats the day, not month+day
format_month_day implies a combined month-and-day output (e.g., "May 1"), but the formatter only uses { day: 'numeric' }, returning "1", "2", etc. The name could confuse a future caller expecting a month component. format_day_of_month or format_day_numeric would be more accurate.
| export function format_month_day(dateParam: Date | string, locale?: string | string[]) { | |
| return new Intl.DateTimeFormat(locale, { day: 'numeric' }).format(normalize_date(dateParam)); | |
| } | |
| export function format_day_of_month(dateParam: Date | string, locale?: string | string[]) { | |
| return new Intl.DateTimeFormat(locale, { day: 'numeric' }).format(normalize_date(dateParam)); | |
| } |
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
|
✅ CI green, Greptile 5/5, all checks passing. Merge-ready — waiting on maintainer merge click. Summary: Hardcoded English weekday/month labels in TimelineBarChart replaced with Intl.DateTimeFormat-backed locale-aware helpers, with DST edge case guard and covered integration tests. |
Summary
TimelineBarChartTesting
npm test -- --runInBand test/unit/time.test.jsContext
This fixes the locale inconsistency reported in
ActivityWatch/aw-server-rust#602. The UI lives inaw-webui, so I am landing the frontend change here first and linking the parent issue back to this PR.