morris / vanilla-todo

A case study on viable techniques for vanilla web development.
https://morris.github.io/vanilla-todo/
ISC License
1.17k stars 54 forks source link

Move forward by one not working #3

Closed anchepiece closed 3 years ago

anchepiece commented 3 years ago

Hi :wave:,

Thanks for creating and open sourcing this case study.

I ran into a discrepancy between the forward and backward date movement using the left and right controls. What is seen that clicking the backward button will move the date back 2 days, while clicking forward has no effect.

The most likely reason is that the seek event listener is not applying a full day of movement once the updated date set with t.setDate(t.getDate() + e.detail) gets formatted with formatDateId.

A simple change like this in TodoStore may be enough to address this case. var t = new Date(state.at + ' 00:00:00');

morris commented 3 years ago

I will take a look! Would you mind sharing the browser you used?

coder543 commented 3 years ago

macOS Chrome, same issue

anchepiece commented 3 years ago

This was replicated in both firefox 82.0 (64-bit) and chrome Version 88.0.4292.2 (Official Build) dev (64-bit)

jcoussard commented 3 years ago

It happens to me too. @anchepiece idea of adding ' 00:00:00' works for me. The backward button also moves by 2 days instead of one. It happens because the seek event calculations don't handle timezone properly. Everyone living on the left side of the Greenwich meridian is affected by this bug! It isn't browser related.

// Assuming state.at is 2020-10-27 and e.detail is 1
var t = new Date(state.at);
// t is Wed Oct 26 2020 00:00:00 GMT-0400 (Eastern Daylight Time)
t.setDate(t.getDate() + e.detail); // 26 + 1 = 27

dispatch({
  at: VT.formatDateId(t), // 2020-10-27
});

Clicking forward yields the original date. Clicking backward goes back 2 days.

morris commented 3 years ago

Ahh I should have asked for time zones. Thanks for reporting this, figuring out the cause and providing the fix! Hope it's fine now. I'll add you to the contributor file or section if that's alright :)

jcoussard commented 3 years ago

I confirm it is fixed, all navigation buttons work as intended now.

anchepiece commented 3 years ago

Glad its working for others too! Thanks again for sharing this project.