dnasir / angular-dateParser

A simple parser that converts date and time strings into Date object
http://dnasir.github.io/angular-dateParser/
MIT License
38 stars 25 forks source link

fix for daylight savings #8

Closed jlowcs closed 10 years ago

jlowcs commented 10 years ago

There was an issue when the date to parse is in ST (resp DT) and today is in DT (resp ST), when there is no 'Z' in the format.

Here is the output in Chrome's console:

> new Date()
Fri Apr 11 2014 12:41:18 GMT+0200 (Paris, Madrid (heure d’été))
> new Date(2001, 0, 1, 12, 0)
Mon Jan 01 2001 12:00:00 GMT+0100 (Paris, Madrid)
> angular.element(document).injector().get("$dateParser")('2014-04-11 12:00', 'yyyy-MM-dd HH:mm')
Fri Apr 11 2014 12:00:00 GMT+0200 (Paris, Madrid (heure d’été))
> angular.element(document).injector().get("$dateParser")('2001-01-01 12:00', 'yyyy-MM-dd HH:mm')
Mon Jan 01 2001 13:00:00 GMT+0100 (Paris, Madrid)

The last one is parsed as "13:00" when it should be parsed as "12:00".

dnasir commented 10 years ago

@jlowcs Thanks for this. I think this is a better solution, rather than doing any calculation when it's not necessary to do so.