From 6105f822b775d4796c90a35c249c757c9e6eff58 Mon Sep 17 00:00:00 2001 From: Zach Gollwitzer Date: Mon, 18 Nov 2024 11:44:41 -0500 Subject: [PATCH] Display chart dates in UTC --- .../controllers/time_series_chart_controller.js | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/app/javascript/controllers/time_series_chart_controller.js b/app/javascript/controllers/time_series_chart_controller.js index 428060ae..0a0c1bee 100644 --- a/app/javascript/controllers/time_series_chart_controller.js +++ b/app/javascript/controllers/time_series_chart_controller.js @@ -51,17 +51,12 @@ export default class extends Controller { _normalizeDataPoints() { this._normalDataPoints = (this.dataValue.values || []).map((d) => ({ ...d, - date: this._parseDate(d.date), + date: new Date(d.date), value: d.value.amount ? +d.value.amount : +d.value, currency: d.value.currency, })); } - _parseDate(dateString) { - const [year, month, day] = dateString.split("-").map(Number); - return new Date(year, month - 1, day); - } - _rememberInitialContainerSize() { this._d3InitialContainerWidth = this._d3Container.node().clientWidth; this._d3InitialContainerHeight = this._d3Container.node().clientHeight; @@ -188,7 +183,7 @@ export default class extends Controller { this._normalDataPoints[this._normalDataPoints.length - 1].date, ]) .tickSize(0) - .tickFormat(d3.timeFormat("%d %b %Y")), + .tickFormat(d3.utcFormat("%d %b %Y")), ) .select(".domain") .remove(); @@ -367,7 +362,7 @@ export default class extends Controller { _tooltipTemplate(datum) { return `
- ${d3.timeFormat("%b %d, %Y")(datum.date)} + ${d3.utcFormat("%b %d, %Y")(datum.date)}