Prechádzať zdrojové kódy

Fix 8706 (#8734)

* heatmap: fix incorrect time for UTC timezone, fixes #8706

* heatmap: fix tests for time format
Alexander Zobnin 8 rokov pred
rodič
commit
97a7081b57

+ 8 - 1
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);
 

+ 7 - 7
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);
 }