fix: Calendar Heatmap day offset (#24989)

This commit is contained in:
Michael S. Molina 2023-08-15 13:35:35 -03:00 committed by GitHub
parent cacad56172
commit 025e4d4772
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 2 deletions

View File

@ -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().