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

Commit

Permalink
fix(dateFilter): make timezone optional
Browse files Browse the repository at this point in the history
Makes the time zone optional in the date filter

Problem with the current R_ISO8601_STR regex was that the time was optional, but the zone was not.
This results in the filter not formatting local date times, which it could easily do.

For example:
2012-08-30 -> formatted
2012-08-30T06:06:06.123Z -> formatted
2012-08-30T06:06:06.123 -> NOT formatted

A simple change in the regex fixes this. Arguably this is closer to the ISO8601 spec which specifies
local dates being in the "current time zone" and not requiring a Z. In any case it behaves more like
a user would expect.
  • Loading branch information
iwein authored and mhevery committed Sep 6, 2012
1 parent eb5fd40 commit 9473780
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ng/filter/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ dateFilter.$inject = ['$locale'];
function dateFilter($locale) {


var R_ISO8601_STR = /^(\d{4})-?(\d\d)-?(\d\d)(?:T(\d\d)(?::?(\d\d)(?::?(\d\d)(?:\.(\d+))?)?)?(Z|([+-])(\d\d):?(\d\d)))?$/;
var R_ISO8601_STR = /^(\d{4})-?(\d\d)-?(\d\d)(?:T(\d\d)(?::?(\d\d)(?::?(\d\d)(?:\.(\d+))?)?)?(Z|([+-])(\d\d):?(\d\d))?)?$/;
function jsonStringToDate(string){
var match;
if (match = string.match(R_ISO8601_STR)) {
Expand Down
3 changes: 3 additions & 0 deletions test/ng/filter/filtersSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,9 @@ describe('filters', function() {

expect(date('20030910T033203-0930', format)).toEqual('2003-09 03');

//no timezone
expect(date('2003-09-10T13:02:03.000', format)).toEqual('2003-09 03');

//no millis
expect(date('2003-09-10T13:02:03Z', format)).toEqual('2003-09 03');

Expand Down

0 comments on commit 9473780

Please sign in to comment.