-
Notifications
You must be signed in to change notification settings - Fork 300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Days getting shifted? #126
Comments
I was seeing this same issue in Gitlab and was able to determine it was based on the user's timestamp, when converting a timestamp that is at midnight (example 1372791600) by doing My data for example had new Date(1413158400 * 1000);
// Sun Oct 12 2014 20:00:00 GMT-0400 (EDT) Should have returned This is no good, because the contributions calendar Gitlab uses is a daily thing, it means all dates will appear to be off by one day, because what should have been Monday Oct 13th at midnight became Sunday Oct 2 at 20:00. So if your server does not consider the user's timezone, which is probably won't, then your client needs to. I fixed this with an afterLoadData: function (timestamps) {
var offset = new Date().getTimezoneOffset() * 60
var results = {}
for (var timestmap in timestamps) {
var commitCount = timestamps[timestamp]
timestmap = parseInt(timestmap, 10)
results[timestamp + offset] = commitCount
})
return results
} |
solid answer @benhutchins ... this issue could/should be closed @wa0x6e |
Lovely answer @benhutchins, and it saved my sanity. However, there are a few bugs in your code snippet. This is my corrected version, which I'm putting here for convenience: afterLoadData: function (timestamps) {
var offset = new Date().getTimezoneOffset() * 60;
var results = {};
for (var timestamp in timestamps) {
var commitCount = timestamps[timestamp];
timestamp = parseInt(timestamp, 10);
console.log(timestamp)
results[timestamp + offset] = commitCount;
};
return results;
} Again, thanks so much for providing the original answer. 😄 |
Thanks for the solution, @benhutchins and @pydanny! There is an additional issue with this solution. I'm in EST timezone, and there is daylight saving time(EDT) change on every March 12th. So when you do offset calculation in EDT time, the dates before March 12th is shift back one day. and there will be a missing date on March 12 in my project. At that time I would rather to use 5-hour-offset instead of 4-hour-offset. |
@voidsteed @benhutchins @pydanny Hey guys, thanks for your help! I've updated const afterLoadData = timestamps => {
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;
} P.S.: It's ES6, but you can easily update it to be ES5 |
I have been debugging this issue for a while and wish I'd found this issue earlier :-) The issue I'm seeing is that the offset from utc appears to be (24 - my timezone offset), so for PST -8, I need to add 24-8 hours. Not sure why yet or if I've done something else which has contributed to the issue, but this afterLoadData and adding 24-8hrs is a working workaround for me. |
Hi,
For some reason, the heatmap is shifting some of the JSON values. I don't think this is related to timezone because all of my events (recorded in EST) occur before 11pm (viewing in central time zone). I suspect that everything is shifted back one day.
I did some debugging, and found that I have the following events on sunday:
Sun 17 @ 1408233600
Sun 7 @ 1410048000
Sun 14 @ 1410652800
Sun 5 @ 1412467200
Sun 9 @ 1415491200
However, the heatmap graphs a lot of sunday events (last row is sunday). I know for sure that the data generated by my backend is correct.

I'm not sure why this is happening. Can someone give me some guidance?
The text was updated successfully, but these errors were encountered: