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

Commit 9473780

Browse files
iweinmhevery
authored andcommitted
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.
1 parent eb5fd40 commit 9473780

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/ng/filter/filters.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ dateFilter.$inject = ['$locale'];
320320
function dateFilter($locale) {
321321

322322

323-
var R_ISO8601_STR = /^(\d{4})-?(\d\d)-?(\d\d)(?:T(\d\d)(?::?(\d\d)(?::?(\d\d)(?:\.(\d+))?)?)?(Z|([+-])(\d\d):?(\d\d)))?$/;
323+
var R_ISO8601_STR = /^(\d{4})-?(\d\d)-?(\d\d)(?:T(\d\d)(?::?(\d\d)(?::?(\d\d)(?:\.(\d+))?)?)?(Z|([+-])(\d\d):?(\d\d))?)?$/;
324324
function jsonStringToDate(string){
325325
var match;
326326
if (match = string.match(R_ISO8601_STR)) {

test/ng/filter/filtersSpec.js

+3
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,9 @@ describe('filters', function() {
258258

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

261+
//no timezone
262+
expect(date('2003-09-10T13:02:03.000', format)).toEqual('2003-09 03');
263+
261264
//no millis
262265
expect(date('2003-09-10T13:02:03Z', format)).toEqual('2003-09 03');
263266

0 commit comments

Comments
 (0)