From 5ac14f633a69f49973b5512780c6ec7752405967 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Fri, 16 Mar 2012 11:28:32 -0700 Subject: fix(json): added support for iso8061 timezone Added support of timezone in dates not just zulu timezone. This fixes issues for date filter which uses json deserialization under the hood. (for now) Closes #/800 --- test/JsonSpec.js | 56 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 29 insertions(+), 27 deletions(-) (limited to 'test/JsonSpec.js') diff --git a/test/JsonSpec.js b/test/JsonSpec.js index df1e428a..e4abeef9 100644 --- a/test/JsonSpec.js +++ b/test/JsonSpec.js @@ -220,42 +220,44 @@ describe('json', 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()); - }); + 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')); + 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')); - //no millis - expect(jsonStringToDate('2003-09-10T13:02:03Z')). - 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')); - //no seconds - expect(jsonStringToDate('2003-09-10T13:02Z')). - toEqual(new Date('Sep 10 2003 13:02:00 GMT')); + expect(jsonStringToDate('20030910T033203-0930')).toEqual(new Date('Sep 10 2003 13:02:03 GMT')); - //no minutes - expect(jsonStringToDate('2003-09-10T13Z')). - toEqual(new Date('Sep 10 2003 13:00:00 GMT')); + //no millis + expect(jsonStringToDate('2003-09-10T13:02:03Z')).toEqual(new Date('Sep 10 2003 13:02:03 GMT')); - //no time - expect(jsonStringToDate('2003-09-10')). - toEqual(new Date('Sep 10 2003 00:00:00 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')); - 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'); - }); + //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() { -- cgit v1.2.3