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

dateFilter uses locale timezone offset for "Z" even when UTC timezone is specified #9359

Closed
niallsmart opened this issue Oct 1, 2014 · 5 comments

Comments

@niallsmart
Copy link
Contributor

I would expect the following expression to be a no-op:

{{ '2012-01-01T00:00:00Z' | date:'yyyy-MM-ddTHH:mm:ssZ':'UTC' }}

However, the "Z" format specifier always uses the locale timezone offset – i.e., ignores the timezone specified to the filter – so in my browser this evaluates to:

2012-01-01T00:00:00-0500
@niallsmart
Copy link
Contributor Author

A hackish way to fix this might be to override the prototype getTimezoneOffset after adjusting the date to UTC.

    if (timezone && timezone === 'UTC') {
      date = new Date(date.getTime());
      date.setMinutes(date.getMinutes() + date.getTimezoneOffset());
      date.getTimezoneOffset = function() { return 0; }; // <- like this
    }

Alternatively, dateFilter needs to special case the Z format specifier.

@niallsmart
Copy link
Contributor Author

PS I'm happy to work up a pull request if you guys would like to suggest a direction the fix should take (special-casing vs overriding prototype).

@jeffbcross
Copy link
Contributor

@tbosch thoughts?

@tbosch tbosch self-assigned this Oct 9, 2014
@tbosch
Copy link
Contributor

tbosch commented Oct 9, 2014

Yes, this is a bug, agree.
Just to make it clear: Only the value that is formatted as the timezone is incorrect, all other values are correct.

@igcarun07
Copy link

Thanks @niallsmart

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

Successfully merging a pull request may close this issue.

4 participants