From 3af1e7ca2ee8c2acd69e5bcbb3ffc1bf51239285 Mon Sep 17 00:00:00 2001 From: Di Peng Date: Thu, 14 Jul 2011 12:02:01 -0700 Subject: feat(filter.date): add support for default datetime formats in en - add support for full,long, medium, short datetime formats in en Breaks MMMMM. now we don't support MMMMM anymore as old implementation differs from Unicode Locale Data format we are following. - removed support for fullDateTime and fullTime as it means too much trouble with full timeZone names - added docs for the new features --- test/FiltersSpec.js | 78 ++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 69 insertions(+), 9 deletions(-) (limited to 'test/FiltersSpec.js') diff --git a/test/FiltersSpec.js b/test/FiltersSpec.js index 594428f6..6bcdb511 100644 --- a/test/FiltersSpec.js +++ b/test/FiltersSpec.js @@ -111,8 +111,10 @@ describe('filter', function() { }); it('should handle mailto:', function() { - expect(linky("mailto:me@example.com").html).toEqual('me@example.com'); - expect(linky("me@example.com").html).toEqual('me@example.com'); + expect(linky("mailto:me@example.com").html). + toEqual('me@example.com'); + expect(linky("me@example.com").html). + toEqual('me@example.com'); expect(linky("send email to me@example.com, but").html). toEqual('send email to me@example.com, but'); }); @@ -123,6 +125,9 @@ describe('filter', function() { var morning = new TzDate(+5, '2010-09-03T12:05:08.000Z'); //7am var noon = new TzDate(+5, '2010-09-03T17:05:08.000Z'); //12pm var midnight = new TzDate(+5, '2010-09-03T05:05:08.000Z'); //12am + var earlyDate = new TzDate(+5, '0001-09-03T05:05:08.000Z'); + var timZoneDate = new TzDate(+5, '2010-09-03T05:05:08.000Z', + 'Mon Sep 3 2010 00:05:08 GMT+0500 (XYZ)'); //12am it('should ignore falsy inputs', function() { expect(filter.date(null)).toBeNull(); @@ -141,24 +146,79 @@ describe('filter', function() { it('should accept various format strings', function() { expect(filter.date(morning, "yy-MM-dd HH:mm:ss")). - toEqual('10-09-03 07:05:08'); + toEqual('10-09-03 07:05:08'); expect(filter.date(midnight, "yyyy-M-d h=H:m:saZ")). - toEqual('2010-9-3 12=0:5:8am0500'); + toEqual('2010-9-3 12=0:5:8am0500'); expect(filter.date(midnight, "yyyy-MM-dd hh=HH:mm:ssaZ")). - toEqual('2010-09-03 12=00:05:08am0500'); + toEqual('2010-09-03 12=00:05:08am0500'); expect(filter.date(noon, "yyyy-MM-dd hh=HH:mm:ssaZ")). - toEqual('2010-09-03 12=12:05:08pm0500'); + toEqual('2010-09-03 12=12:05:08pm0500'); + + expect(filter.date(timZoneDate, "yyyy-MM-dd hh=HH:mm:ss a z")). + toEqual('2010-09-03 12=00:05:08 am XYZ'); expect(filter.date(noon, "EEE, MMM d, yyyy")). - toEqual('Fri, Sep 3, 2010'); + toEqual('Fri, Sep 3, 2010'); + + expect(filter.date(noon, "EEEE, MMMM dd, yyyy")). + toEqual('Friday, September 03, 2010'); + + expect(filter.date(earlyDate, "MMMM dd, y")). + toEqual('September 03, 1'); + }); + + it('should accept default formats', function() { + + expect(filter.date(timZoneDate, "long")). + toEqual('September 3, 2010 12:05:08 am XYZ'); + + expect(filter.date(noon, "medium")). + toEqual('Sep 3, 2010 12:05:08 pm'); + + expect(filter.date(noon, "short")). + toEqual('9/3/10 12:05 pm'); + + expect(filter.date(noon, "fullDate")). + toEqual('Friday, September 3, 2010'); + + expect(filter.date(noon, "longDate")). + toEqual('September 3, 2010'); - expect(filter.date(noon, "EEEE, MMMMM dd, yyyy")). - toEqual('Friday, September 03, 2010'); + expect(filter.date(noon, "mediumDate")). + toEqual('Sep 3, 2010'); + + expect(filter.date(noon, "shortDate")). + toEqual('9/3/10'); + + expect(filter.date(timZoneDate, "longTime")). + toEqual('12:05:08 am XYZ'); + + expect(filter.date(noon, "mediumTime")). + toEqual('12:05:08 pm'); + + expect(filter.date(noon, "shortTime")). + toEqual('12:05 pm'); + }); + + + it('should parse timezone identifier from various toString values', function() { + //chrome and firefox format + expect(filter.date(new TzDate(+5, '2010-09-03T17:05:08.000Z', + 'Mon Sep 3 2010 17:05:08 GMT+0500 (XYZ)'), "z")).toBe('XYZ'); + + //opera format + expect(filter.date(new TzDate(+5, '2010-09-03T17:05:08.000Z', + '2010-09-03T17:05:08Z'), "z")).toBe('0500'); + + //ie 8 format + expect(filter.date(new TzDate(+5, '2010-09-03T17:05:08.000Z', + 'Mon Sep 3 17:05:08 XYZ 2010'), "z")).toBe('XYZ'); }); + it('should be able to parse ISO 8601 dates/times using', function() { var isoString = '2010-09-03T05:05:08.872Z'; expect(filter.date(isoString)). -- cgit v1.2.3