diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/JsonSpec.js | 52 | ||||
| -rw-r--r-- | test/ng/filter/filtersSpec.js | 32 |
2 files changed, 27 insertions, 57 deletions
diff --git a/test/JsonSpec.js b/test/JsonSpec.js index e4abeef9..ad0cb415 100644 --- a/test/JsonSpec.js +++ b/test/JsonSpec.js @@ -72,9 +72,8 @@ describe('json', function() { }); it('should serialize UTC dates', function() { - var date = jsonStringToDate('2009-10-09T01:02:03.027Z'); + var date = new angular.mock.TzDate(-1, '2009-10-09T01:02:03.027Z'); expect(toJson(date)).toEqual('"2009-10-09T01:02:03.027Z"'); - expect(fromJson('"2009-10-09T01:02:03.027Z"').getTime()).toEqual(date.getTime()); }); it('should prevent recursion', function() { @@ -156,17 +155,7 @@ describe('json', function() { expect(fromJson('{}', true)).toEqual({}); expect(spy).toHaveBeenCalled(); }); - - - it('should convert timestamp strings to Date objects', function() { - expect(fromJson('"2010-12-22T17:23:17.974Z"', true) instanceof Date).toBe(true); - expect(fromJson('["2010-12-22T17:23:17.974Z"]', true)[0] instanceof Date).toBe(true); - expect(fromJson('{"t":"2010-12-22T17:23:17.974Z"}', true).t instanceof Date).toBe(true); - expect(fromJson('{"t":["2010-12-22T17:23:17.974Z"]}', true).t[0] instanceof Date).toBe(true); - expect(fromJson('{"t":{"t":"2010-12-22T17:23:17.974Z"}}', true).t.t instanceof Date).toBe(true); - }); }); - } @@ -220,45 +209,6 @@ describe('json', function() { }); - describe('iso 8061 date', function() { - it('should read/write to date', function() { - var date = new Date('Sep 10 2003 13:02:03 GMT'); - expect(jsonDateToString(date)).toBe('2003-09-10T13:02:03.000Z'); - expect(jsonStringToDate(jsonDateToString(date)).getTime()).toBe(date.getTime()); - }); - - - it('should convert to date', function() { - //full ISO8061 - expect(jsonStringToDate('2003-09-10T13:02:03.000Z')).toEqual(new Date('Sep 10 2003 13:02:03 GMT')); - - expect(jsonStringToDate('2003-09-10T13:02:03.000+00:00')).toEqual(new Date('Sep 10 2003 13:02:03 GMT')); - - expect(jsonStringToDate('20030910T033203-0930')).toEqual(new Date('Sep 10 2003 13:02:03 GMT')); - - //no millis - expect(jsonStringToDate('2003-09-10T13:02:03Z')).toEqual(new Date('Sep 10 2003 13:02:03 GMT')); - - //no seconds - expect(jsonStringToDate('2003-09-10T13:02Z')).toEqual(new Date('Sep 10 2003 13:02:00 GMT')); - - //no minutes - expect(jsonStringToDate('2003-09-10T13Z')).toEqual(new Date('Sep 10 2003 13:00:00 GMT')); - - //no time - expect(jsonStringToDate('2003-09-10')).toEqual(new Date('Sep 10 2003 00:00:00 GMT')); - - expect(jsonStringToDate('2011-12-28T13:02:09-08:00')).toEqual(new Date('Dec 28 2011 21:02:09 GMT')); - }); - - - it('should parse date', function() { - var date = jsonStringToDate('2003-09-10T13:02:03.000Z'); - expect(jsonDateToString(date)).toBe('2003-09-10T13:02:03.000Z'); - expect(jsonStringToDate('str')).toBe('str'); - }); - }); - describe('string', function() { it('should quote', function() { expect(quoteUnicode('a')).toBe('"a"'); 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'); + }); }); }); |
