JohannesHoppe / angular-date-value-accessor

Home of the Angular DateValueAccessor for <input type="date">
http://johanneshoppe.github.io/angular-date-value-accessor/
MIT License
78 stars 19 forks source link

local dates #6

Closed elemental21 closed 7 years ago

elemental21 commented 7 years ago

I realize this isn't really an issue, but I'm curious if you could include how to get the local date to display instead of GMT. I've tried moment.js with .format() and it doesn't work unless I manually take off the 05:00 from the ISO date: 2017-03-01T08:24:24-05:00 before passing it to the Date object that is assigned to my FormControl.

JohannesHoppe commented 7 years ago

This is funny, usually people want to have UTC dates everywhere in their software. You will have to convert date objects back and forth, unfortunately this is always the same... :disappointed:

elemental21 commented 7 years ago

Hopefully you can point me in the right direction here. I don't quite understand. I have a form that sets a date field for an appointment to a default date, which is supposed to be the current local time of the user, then lets them adjust it as necessary. Right now when I pass in 'new Date()' for my FormControl which is hooked to my type="date" input it displays to the user as GMT/UTC time. Are you saying people usually want this? I get storing it that way. I'm assume I'm misunderstanding.

JohannesHoppe commented 7 years ago

First: This helper is for dates. It does not show a time! Controls for date + time are another story.

Now your question: You are not misunderstanding me. Usually people agree to one time zone to get things sorted. They can decide for: a) Their time zone (which is bad for internationalization) a) Coordinated Universal Time, which has no silly daylight saving time, too.

Since we don't have a real "date without time" type in JS, the time 0:00 midnight is used to represent just a date. This is what your browser is supposed to do on <input type="date"> This fits perfectly, because all dates in JS are UTC. However, the representation of dates (e.g. toString()) is done in the users time zone. This can lead to big confusion. :wink:

It's a good practice to treat dates everywhere (backend + fronted + database) as UTC. Everything else will lead to big problems, e.g. when you switch server locations.

elemental21 commented 7 years ago

Thanks for the explanation Johannes

JohannesHoppe commented 3 years ago

reactive-works-local

The latest version finally ships with support for timezone / local dates! The new accessor is called LocalDateValueAccessor. Read more at:

https://github.com/JohannesHoppe/angular-date-value-accessor/releases/tag/v.1.2.0