diff options
| author | Iwein Fuld | 2012-08-30 06:39:52 +0200 |
|---|---|---|
| committer | Misko Hevery | 2012-09-06 15:49:49 -0700 |
| commit | a631ceb223392244d6241c5bb44712ef802f0c98 (patch) | |
| tree | 2d14baf7760364c87a6c4e4e723f597b596f11db | |
| parent | a713928210dc906fd80014cb57ff4efe80a02537 (diff) | |
| download | angular.js-a631ceb223392244d6241c5bb44712ef802f0c98.tar.bz2 | |
fix(dateFilter): make timezone optional
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.
| -rw-r--r-- | src/ng/filter/filters.js | 2 | ||||
| -rw-r--r-- | test/ng/filter/filtersSpec.js | 3 |
2 files changed, 4 insertions, 1 deletions
diff --git a/src/ng/filter/filters.js b/src/ng/filter/filters.js index b3792171..376afd85 100644 --- a/src/ng/filter/filters.js +++ b/src/ng/filter/filters.js @@ -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)) { diff --git a/test/ng/filter/filtersSpec.js b/test/ng/filter/filtersSpec.js index 9e0a408a..883e91f6 100644 --- a/test/ng/filter/filtersSpec.js +++ b/test/ng/filter/filtersSpec.js @@ -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'); |
