eight04 / angular-datetime

A directive to add the behavior of datetime input on unsupported browsers.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Focus in input causes wrong date object

troxler opened this issue · comments

Setting the focus in an input element sets its model value to a date object of the current moment. This, however, is wrong when the input does not show the complete date. For example, I have an input with datetime="longDate". Clicking it will set its model value something like "2016-02-15T20:22:40.808Z". It should, however, be "2016-02-14T23:00:00.000Z" (February 15. minus one hour because my timezone is +1).

commented

I think setting to current time is enough. You still stay at 2/15 anyway. Also the time part is truncated on the input element.

I disagree. Without explicitly stripping the time part, one might run into problems with equality check of different dates, and strange sequence order.

commented

👍

Maybe we actually need is to add a default value. It might look like min, max options:

<input type="text" datetime="longDate" default="Jan 1, 2000">
commented

But while comparing different date, it still runs into problem if only time is used.

<input type="text" datetime="HH:mm:ss" default="Jan 1, 2000">
<input type="text" datetime="HH:mm:ss" default="Jan 2, 2000">

They look like the same but actually the second one is greater. To solve it you might need to implement a set of comparing function actually meeting your needs.

commented

Fixed in 2.2.0

This is probably quite hard to solve for every single usecase. But I like your approach, thank you for that.