From ac4318a2fa5c6d306dbc19466246292a81767fca Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Mon, 26 Mar 2012 23:38:20 -0700 Subject: refactor(fromJson/date filter): move date string logic to date filter Breaks angular.fromJson which doesn't deserialize date strings into date objects. This was done to make fromJson compatible with JSON.parse. If you do require the old behavior - if at all neeeded then because of json deserialization of XHR responses - then please create a custom $http transform: $httpProvider.defaults.transformResponse.push(function(data) { // recursively parse dates from data object here // see code removed in this diff for hints }); Closes #202 --- test/ng/filter/filtersSpec.js | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) (limited to 'test/ng') diff --git a/test/ng/filter/filtersSpec.js b/test/ng/filter/filtersSpec.js index 98651c58..9ea200a3 100644 --- a/test/ng/filter/filtersSpec.js +++ b/test/ng/filter/filtersSpec.js @@ -267,14 +267,34 @@ describe('filters', function() { toEqual('12:05 PM'); }); - it('should be able to parse ISO 8601 dates/times using', function() { - var isoString = '2010-09-03T05:05:08.872Z'; - expect(date(isoString)). - toEqual(date(isoString, 'mediumDate')); - }); - it('should parse format ending with non-replaced string', function() { expect(date(morning, 'yy/xxx')).toEqual('10/xxx'); }); + + + it('should support various iso8061 date strings as input', function() { + var format = 'yyyy-MM ss'; + + //full ISO8061 + expect(date('2003-09-10T13:02:03.000Z', format)).toEqual('2003-09 03'); + + expect(date('2003-09-10T13:02:03.000+00:00', format)).toEqual('2003-09 03'); + + expect(date('2003-09-10T13:02:03-08:00', format)).toEqual('2003-09 03'); + + expect(date('20030910T033203-0930', format)).toEqual('2003-09 03'); + + //no millis + expect(date('2003-09-10T13:02:03Z', format)).toEqual('2003-09 03'); + + //no seconds + expect(date('2003-09-10T13:02Z', format)).toEqual('2003-09 00'); + + //no minutes + expect(date('2003-09-10T13Z', format)).toEqual('2003-09 00'); + + //no time + expect(date('2003-09-10', format)).toEqual('2003-09 00'); + }); }); }); -- cgit v1.2.3