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

Is there any support for timezone? #13

Closed matteogrolla closed 3 years ago

matteogrolla commented 6 years ago

I'm looking at the demo: https://johanneshoppe.github.io/angular-date-value-accessor/ ReleaseDate on the input: 27/09/2016 is mapped to: 2016-09-27T00:00:00.000Z but I need input to be interpreted in local time and should map to 2016-09-26T22:00:00.000Z

JohannesHoppe commented 6 years ago

Good point. The goal of this library is a "DateValueAccessor for <input type="date">". See this article: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/date

You want a DateValueAccessor for <input type="datetime-local">. See this: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/datetime-local

It shouldn't be hard to implement this, but I have no time to do this. I'm happy about any PR! 😉

matteogrolla commented 6 years ago

Hi Johannes, I only want user to choose a date, so type="date" but I want the model to be a local date ( a gmt date is only usefull to drive me crazy) I can contribute back the modified date-value-accessor.ts file if you want

JohannesHoppe commented 6 years ago

I see. But this would be against the spec. In JavaScript-world we tread everything as UTC and usually selecting a date from an input-field means zero o'clock zulu time. Same story on the backend!

Your plan highly depends on the time of the browser, which can bogus. Are you sure that you really want to go that path?

matteogrolla commented 6 years ago

my needs are: let's say I have date 2016-09-26T22:00:00.000Z coming from the backend I want to show it in an input type=date it should show 27/09/2016 and if the user modifies the date, I'd like it to be interpreted as a local date

the information I add is timezone, not time (if the browser time is wrong nothing changes, if the browser timezone is wrong... user fault?) this way when I read a date I don't have to ask myself if it's a GMT date, it represents a precise instant and I can interpret it easily in local timezone (or any other) If I'm missing something please tell me

Il giorno mer 4 lug 2018 alle ore 15:15 Johannes Hoppe < notifications@github.com> ha scritto:

Reopened #13 https://github.com/JohannesHoppe/angular-date-value-accessor/issues/13.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/JohannesHoppe/angular-date-value-accessor/issues/13#event-1716314268, or mute the thread https://github.com/notifications/unsubscribe-auth/ABEJLPljgrX1KyVt4wAB0C3oq4_XJmrMks5uDL_9gaJpZM4VCPeM .

spierala commented 3 years ago

@JohannesHoppe Also came across this issue. The date input with useValueAsDate behaves differently than e.g. the Material Date Picker or also the DatePipe in other timezones. E.g. Hawaai.

See the screenshot: image

Stackblitz here: https://stackblitz.com/edit/angular-date-valude-accessor-mat-datepicker?file=src%2Fapp%2Fdatepicker-overview-example.ts

Maybe the README should mention that the DateValueAccessor is not aware of the local timezone?

JohannesHoppe commented 3 years ago

Yep, that's the way how <input type="date"> is implemented in the browser.

I would be happy for any kind of PR.

  1. an update of the documentation
  2. or an additional accessor for <input type="datetime-local">
  3. or both! 😄
spierala commented 3 years ago

I tried to create a DateLocalValueAccessor :) You can have a look here:

https://stackblitz.com/edit/angular-date-valude-accessor-mat-datepicker?file=src%2Fapp%2Fdate-local-value-accessor%2Fdate-local-value-accessor.directive.ts

Now the input type date behaves like the Material Date Picker / Angular Date Pipe. If you like the solution, then I could create a PR.

spierala commented 3 years ago

@JohannesHoppe, did you see my last message? What do you think of creating a second DateValueAccessor (e.g. "DateLocalValueAccessor") next to the existing one which is well aware of the local timezone?

JohannesHoppe commented 3 years ago

@spierala Yes, and I'm sorry because of the delay. Right now I'm fighting with this: https://github.com/angular-schule/angular-cli-ghpages/pull/120

Of course, I really like your work! 😃 👍 I would be very happy about a PR. Would it be also possible to document the differences between the two accessors and to show the readers when to use which solution?

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