From 97a7081b5735af8bb746ffd0e797f946f990ab34 Mon Sep 17 00:00:00 2001 From: Alexander Zobnin Date: Thu, 29 Jun 2017 11:40:28 +0300 Subject: [PATCH] Fix 8706 (#8734) * heatmap: fix incorrect time for UTC timezone, fixes #8706 * heatmap: fix tests for time format --- public/app/plugins/panel/heatmap/rendering.ts | 9 ++++++++- .../plugins/panel/heatmap/specs/renderer_specs.ts | 14 +++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/public/app/plugins/panel/heatmap/rendering.ts b/public/app/plugins/panel/heatmap/rendering.ts index 94903cfcb81..b928173eafe 100644 --- a/public/app/plugins/panel/heatmap/rendering.ts +++ b/public/app/plugins/panel/heatmap/rendering.ts @@ -100,10 +100,17 @@ export default function link(scope, elem, attrs, ctrl) { let ticks = chartWidth / DEFAULT_X_TICK_SIZE_PX; let grafanaTimeFormatter = grafanaTimeFormat(ticks, timeRange.from, timeRange.to); + let timeFormat; + let dashboardTimeZone = ctrl.dashboard.getTimezone(); + if (dashboardTimeZone === 'utc') { + timeFormat = d3.utcFormat(grafanaTimeFormatter); + } else { + timeFormat = d3.timeFormat(grafanaTimeFormatter); + } let xAxis = d3.axisBottom(xScale) .ticks(ticks) - .tickFormat(d3.timeFormat(grafanaTimeFormatter)) + .tickFormat(timeFormat) .tickPadding(X_AXIS_TICK_PADDING) .tickSize(chartHeight); diff --git a/public/app/plugins/panel/heatmap/specs/renderer_specs.ts b/public/app/plugins/panel/heatmap/specs/renderer_specs.ts index 9ca7297e9b6..5d3eb665e55 100644 --- a/public/app/plugins/panel/heatmap/specs/renderer_specs.ts +++ b/public/app/plugins/panel/heatmap/specs/renderer_specs.ts @@ -153,11 +153,11 @@ describe('grafanaHeatmap', function () { it('should draw correct X axis', function () { var xTicks = getTicks(ctx.element, ".axis-x"); let expectedTicks = [ - formatLocalTime("01 Mar 2017 10:00:00"), - formatLocalTime("01 Mar 2017 10:15:00"), - formatLocalTime("01 Mar 2017 10:30:00"), - formatLocalTime("01 Mar 2017 10:45:00"), - formatLocalTime("01 Mar 2017 11:00:00") + formatTime("01 Mar 2017 10:00:00"), + formatTime("01 Mar 2017 10:15:00"), + formatTime("01 Mar 2017 10:30:00"), + formatTime("01 Mar 2017 10:45:00"), + formatTime("01 Mar 2017 11:00:00") ]; expect(xTicks).to.eql(expectedTicks); }); @@ -261,7 +261,7 @@ function getTicks(element, axisSelector) { }).get(); } -function formatLocalTime(timeStr) { +function formatTime(timeStr) { let format = "HH:mm"; - return moment.utc(timeStr, 'DD MMM YYYY HH:mm:ss').local().format(format); + return moment.utc(timeStr, 'DD MMM YYYY HH:mm:ss').format(format); }