hftlclub / node-iltis

Node.js backend for ILTIS
MIT License
1 stars 0 forks source link

Event time jumps back for one hour #12

Closed fmalcher closed 7 years ago

fmalcher commented 7 years ago

After saving the event time, it gets stored with one hour less than wanted.

This problem has its roots in the backend. See the following example:

Edit an event. Choose "19:00" as time. The following ISO string is sent to the server: bildschirmfoto 2017-03-04 um 01 31 30

This is completely correct, since new Date('2017-03-03T18:00:19.000Z') leads to a date object with hours set to 19 (due to the time zone).

However, when retrieving the event from the server, the ISO string is different: bildschirmfoto 2017-03-04 um 01 33 42

Looks like the problem is with MySQL?

rweisse commented 7 years ago

It seems to be that both, frontend and mysql, are setting the time one hour back due to the time zone settings of the operating system. The backend does not manipulate the date object (tested). We could probably turn of this function in mysql. But I don't know what side-effects this may have to timestamps. Maybe it's better to turn of the timezone settings in the frontend-formular.

fmalcher commented 7 years ago

As users' browsers are not predictable I prefer changing it in the backend since this is the only instance we can control completely. In my opinion, the frontend is not actually setting the time back. Converting the resulting ISO string back to a Date object gives us the original time.

fmalcher commented 7 years ago

Difficult... This one suggests to use DATETIME only:

Trusting your server's time zone settings and MySQL's time zone conversion abilities is a bad idea. Instead, use datetime fields and store UTC formatted values only.

(http://www.webdevelopersdiary.com/blog/good-to-know-how-to-properly-store-date-and-time-values-in-mysql)

What do you think? @rweisse

rweisse commented 7 years ago

Ok, I'll read this. Meanwhile you should read this: https://www.ericluwj.com/2015/11/06/angularui-ui-bootstrap-datepicker-and-timepicker-neutral-timezone.html

rweisse commented 7 years ago

The reason for this problem was neither the frontend nor the database. The node.js mysql-module converts typescript date objects into UTC time again. Preconverting it into a locale date string fixed this issue: new Date(obj.datetime).toLocaleString();