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

* heatmap: fix tests for time format
This commit is contained in:
Alexander Zobnin 2017-06-29 11:40:28 +03:00 committed by Daniel Lee
parent 8634c9d457
commit 97a7081b57
2 changed files with 15 additions and 8 deletions

View File

@ -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);

View File

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