From f3629e14a8d8d077f01d3bd69fb28e6550fed5b1 Mon Sep 17 00:00:00 2001 From: "Michael S. Molina" Date: Tue, 15 Aug 2023 11:29:02 -0300 Subject: [PATCH] fix: Calendar Heatmap day offset --- .../src/vendor/cal-heatmap.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/superset-frontend/plugins/legacy-plugin-chart-calendar/src/vendor/cal-heatmap.js b/superset-frontend/plugins/legacy-plugin-chart-calendar/src/vendor/cal-heatmap.js index 760bf0ce2b0c4..482a315392679 100644 --- a/superset-frontend/plugins/legacy-plugin-chart-calendar/src/vendor/cal-heatmap.js +++ b/superset-frontend/plugins/legacy-plugin-chart-calendar/src/vendor/cal-heatmap.js @@ -296,8 +296,21 @@ var CalHeatMap = function () { // Used mainly to convert the datas if they're not formatted like expected // Takes the fetched "data" object as argument, must return a json object // formatted like {timestamp:count, timestamp2:count2}, - afterLoadData: function (data) { - return data; + afterLoadData: function (timestamps) { + // See https://github.com/wa0x6e/cal-heatmap/issues/126#issuecomment-373301803 + const stdTimezoneOffset = date => { + const jan = new Date(date.getFullYear(), 0, 1); + const jul = new Date(date.getFullYear(), 6, 1); + return Math.max(jan.getTimezoneOffset(), jul.getTimezoneOffset()); + }; + const offset = stdTimezoneOffset(new Date()) * 60; + let results = {}; + for (let timestamp in timestamps) { + const value = timestamps[timestamp]; + timestamp = parseInt(timestamp, 10); + results[timestamp + offset] = value; + } + return results; }, // Callback triggered after calling and completing update().