Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

date filter backdates dates if time is not specified #847

Closed
mhevery opened this issue Apr 2, 2012 · 2 comments · Fixed by #1782
Closed

date filter backdates dates if time is not specified #847

mhevery opened this issue Apr 2, 2012 · 2 comments · Fixed by #1782
Labels

Comments

@mhevery
Copy link
Contributor

mhevery commented Apr 2, 2012

{{ '2012-04-01' | date:'d MMM yyyy' }} renders as 31 Mar 2012

http://plnkr.co/edit/pdoczJeLZoCo6CRuwUWi?p=preview

this issue only occurs for clients in timezones before GMT (like PT for example)

@IgorMinar
Copy link
Contributor

the question is how this should actually behave so that we don't introduce new timezone bugs...

  • {{ '2012-04-01' | date:'d MMM yyyy' }} should always render as 1 Apr 2012 regardless of the timezone
  • {{ '2012-04-01 0:0:0' | date:'d MMM yyyy' }} should assume that the time is in GMT so the output is timezone-dependent
  • {{ '2012-04-01 0:0:0 +0200' | date:'d MMM yyyy' }} should assume that the time is in GMT+2 so the output is timezone-dependent.

I think that this is a reasonable behavior

@IgorMinar
Copy link
Contributor

actually it turns out that ISO8601 states that if a timezone is not specified the time/date is in the local time, so {{ '2012-04-01 0:0:0' | date:'d MMM yyyy' }} should always render as 1 Apr 2012.

The odd thing is the javascript's Date constructor is quite screwed up (at least in V8):

> new Date('2012-04-01')
Sat Mar 31 2012 17:00:00 GMT-0700 (PDT)
> new Date('2012-04-01T00:00:00')
Sat Mar 31 2012 17:00:00 GMT-0700 (PDT)

> new Date('2012-04-01 0:0:0')
Sun Apr 01 2012 00:00:00 GMT-0700 (PDT)
> new Date('2012-04-01 00:00:00')
Sun Apr 01 2012 00:00:00 GMT-0700 (PDT)

> new Date('2012-04-01T00:00:00Z')
Sat Mar 31 2012 17:00:00 GMT-0700 (PDT)
> new Date('2012-04-01 00:00:00Z')
Sat Mar 31 2012 17:00:00 GMT-0700 (PDT)

notice that in some cases when the timezone is not specified the date/time is parsed as local, other times its parsed as UTC.

jamessharp pushed a commit to jamessharp/angular.js that referenced this issue Jan 18, 2013
previously we were always parsing the string input as UTC which cased issues like:

{{ '2012-04-01' | date:'d MMM yyyy' }} renders as 31 Mar 2012

BREAKING CHANGE: string input without timezone info is now parsed as local time/date

Closes angular#847
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants