Skip to content

Commit 37b5c5c

Browse files
committed
break(date): remove support for 'long', 'longtime' date formats and 'z' flag
The support for the 'z' formatting flag was removed becase the timezone info can't be retrieved from the browser apis (except for en-US locale on some but not all browsers). For this reason we don't want to support this flag at all. Related to this, since the 'long' and 'longtime' datetime formats require the 'z' flag in the formatting string, we are removing support for this format as well.
1 parent 966cbd4 commit 37b5c5c

5 files changed

Lines changed: 13 additions & 65 deletions

File tree

src/angular-mocks.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ function MockLogFactory() {
439439
* </pre>
440440
*
441441
*/
442-
function TzDate(offset, timestamp, toStringVal) {
442+
function TzDate(offset, timestamp) {
443443
if (angular.isString(timestamp)) {
444444
var tsStr = timestamp;
445445

@@ -463,10 +463,6 @@ function TzDate(offset, timestamp, toStringVal) {
463463
return this.date.getTime() - this.offsetDiff;
464464
};
465465

466-
this.toString = function() {
467-
return toStringVal;
468-
};
469-
470466
this.toLocaleDateString = function() {
471467
return this.date.toLocaleDateString();
472468
};
@@ -537,8 +533,6 @@ function TzDate(offset, timestamp, toStringVal) {
537533
'toLocaleTimeString', 'toSource', 'toString', 'toTimeString', 'toUTCString', 'valueOf'];
538534

539535
angular.forEach(unimplementedMethods, function(methodName) {
540-
if (methodName == 'toString' && toStringVal) return;
541-
542536
self[methodName] = function() {
543537
throw {
544538
name: "MethodNotImplemented",

src/filters.js

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -215,16 +215,10 @@ function dateStrGetter(name, shortForm) {
215215
};
216216
}
217217

218-
function timeZoneGetter(numFormat) {
219-
return function(date) {
220-
var timeZone;
221-
if (numFormat || !(timeZone = GET_TIME_ZONE.exec(date.toString()))) {
222-
var offset = date.getTimezoneOffset();
223-
return padNumber(offset / 60, 2) + padNumber(Math.abs(offset % 60), 2);
224-
}
225-
return timeZone[0];
226-
};
227-
}
218+
function timeZoneGetter(date) {
219+
var offset = date.getTimezoneOffset();
220+
return padNumber(offset / 60, 2) + padNumber(Math.abs(offset % 60), 2);
221+
};
228222

229223
function ampmGetter(date, formats) {
230224
return date.getHours() < 12 ? formats.AMPMS[0] : formats.AMPMS[1];
@@ -251,8 +245,7 @@ var DATE_FORMATS = {
251245
EEEE: dateStrGetter('Day'),
252246
EEE: dateStrGetter('Day', true),
253247
a: ampmGetter,
254-
z: timeZoneGetter(false),
255-
Z: timeZoneGetter(true)
248+
Z: timeZoneGetter
256249
};
257250

258251
var GET_TIME_ZONE = /[A-Z]{3}(?![+\-])/;
@@ -293,13 +286,10 @@ var NUMBER_STRING = /^\d+$/;
293286
* * `'s'`: Second in minute (0-59)
294287
* * `'a'`: am/pm marker
295288
* * `'Z'`: 4 digit (+sign) representation of the timezone offset (-1200-1200)
296-
* * `'z'`: short form of current timezone name (e.g. PDT)
297289
*
298290
* `format` string can also be one of the following predefined
299291
* {@link guide/dev_guide.i18n localizable formats}:
300292
*
301-
* * `'long'`: equivalent to `'MMMM d, y h:mm:ss a z'` for en_US locale
302-
* (e.g. September 3, 2010 12:05:08 pm PDT)
303293
* * `'medium'`: equivalent to `'MMM d, y h:mm:ss a'` for en_US locale
304294
* (e.g. Sep 3, 2010 12:05:08 pm)
305295
* * `'short'`: equivalent to `'M/d/yy h:mm a'` for en_US locale (e.g. 9/3/10 12:05 pm)
@@ -308,7 +298,6 @@ var NUMBER_STRING = /^\d+$/;
308298
* * `'longDate'`: equivalent to `'MMMM d, y'` for en_US locale (e.g. September 3, 2010
309299
* * `'mediumDate'`: equivalent to `'MMM d, y'` for en_US locale (e.g. Sep 3, 2010)
310300
* * `'shortDate'`: equivalent to `'M/d/yy'` for en_US locale (e.g. 9/3/10)
311-
* * `'longTime'`: equivalent to `'h:mm:ss a z'` for en_US locale (e.g. 12:05:08 pm PDT)
312301
* * `'mediumTime'`: equivalent to `'h:mm:ss a'` for en_US locale (e.g. 12:05:08 pm)
313302
* * `'shortTime'`: equivalent to `'h:mm a'` for en_US locale (e.g. 12:05 pm)
314303
*

src/service/locale.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,12 @@ angularServiceInject('$locale', function() {
5050
DAY: 'Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday'.split(','),
5151
SHORTDAY: 'Sun,Mon,Tue,Wed,Thu,Fri,Sat'.split(','),
5252
AMPMS: ['AM','PM'],
53-
long: 'MMMM d, y h:mm:ss a z',
5453
medium: 'MMM d, y h:mm:ss a',
5554
short: 'M/d/yy h:mm a',
5655
fullDate: 'EEEE, MMMM d, y',
5756
longDate: 'MMMM d, y',
5857
mediumDate: 'MMM d, y',
5958
shortDate: 'M/d/yy',
60-
longTime: 'h:mm:ss a z',
6159
mediumTime: 'h:mm:ss a',
6260
shortTime: 'h:mm a'
6361
}

test/FiltersSpec.js

Lines changed: 7 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,6 @@ describe('filter', function() {
195195
var noon = new TzDate(+5, '2010-09-03T17:05:08.000Z'); //12pm
196196
var midnight = new TzDate(+5, '2010-09-03T05:05:08.000Z'); //12am
197197
var earlyDate = new TzDate(+5, '0001-09-03T05:05:08.000Z');
198-
var timZoneDate = new TzDate(+5, '2010-09-03T05:05:08.000Z',
199-
'Mon Sep 3 2010 00:05:08 GMT+0500 (XYZ)'); //12am
200198

201199
var context, date;
202200

@@ -225,16 +223,13 @@ describe('filter', function() {
225223
toEqual('10-09-03 07:05:08');
226224

227225
expect(date(midnight, "yyyy-M-d h=H:m:saZ")).
228-
toEqual('2010-9-3 12=0:5:8am0500');
226+
toEqual('2010-9-3 12=0:5:8AM0500');
229227

230228
expect(date(midnight, "yyyy-MM-dd hh=HH:mm:ssaZ")).
231-
toEqual('2010-09-03 12=00:05:08am0500');
229+
toEqual('2010-09-03 12=00:05:08AM0500');
232230

233231
expect(date(noon, "yyyy-MM-dd hh=HH:mm:ssaZ")).
234-
toEqual('2010-09-03 12=12:05:08pm0500');
235-
236-
expect(date(timZoneDate, "yyyy-MM-dd hh=HH:mm:ss a z")).
237-
toEqual('2010-09-03 12=00:05:08 am XYZ');
232+
toEqual('2010-09-03 12=12:05:08PM0500');
238233

239234
expect(date(noon, "EEE, MMM d, yyyy")).
240235
toEqual('Fri, Sep 3, 2010');
@@ -258,14 +253,11 @@ describe('filter', function() {
258253

259254
it('should accept default formats', function() {
260255

261-
expect(date(timZoneDate, "long")).
262-
toEqual('September 3, 2010 12:05:08 am XYZ');
263-
264256
expect(date(noon, "medium")).
265-
toEqual('Sep 3, 2010 12:05:08 pm');
257+
toEqual('Sep 3, 2010 12:05:08 PM');
266258

267259
expect(date(noon, "short")).
268-
toEqual('9/3/10 12:05 pm');
260+
toEqual('9/3/10 12:05 PM');
269261

270262
expect(date(noon, "fullDate")).
271263
toEqual('Friday, September 3, 2010');
@@ -279,32 +271,13 @@ describe('filter', function() {
279271
expect(date(noon, "shortDate")).
280272
toEqual('9/3/10');
281273

282-
expect(date(timZoneDate, "longTime")).
283-
toEqual('12:05:08 am XYZ');
284-
285274
expect(date(noon, "mediumTime")).
286-
toEqual('12:05:08 pm');
275+
toEqual('12:05:08 PM');
287276

288277
expect(date(noon, "shortTime")).
289-
toEqual('12:05 pm');
278+
toEqual('12:05 PM');
290279
});
291280

292-
293-
it('should parse timezone identifier from various toString values', function() {
294-
//chrome and firefox format
295-
expect(date(new TzDate(+5, '2010-09-03T17:05:08.000Z',
296-
'Mon Sep 3 2010 17:05:08 GMT+0500 (XYZ)'), "z")).toBe('XYZ');
297-
298-
//opera format
299-
expect(date(new TzDate(+5, '2010-09-03T17:05:08.000Z',
300-
'2010-09-03T17:05:08Z'), "z")).toBe('0500');
301-
302-
//ie 8 format
303-
expect(date(new TzDate(+5, '2010-09-03T17:05:08.000Z',
304-
'Mon Sep 3 17:05:08 XYZ 2010'), "z")).toBe('XYZ');
305-
});
306-
307-
308281
it('should be able to parse ISO 8601 dates/times using', function() {
309282
var isoString = '2010-09-03T05:05:08.872Z';
310283
expect(date(isoString)).

test/angular-mocksSpec.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,6 @@ describe('mocks', function(){
123123
});
124124

125125

126-
it('should fake toString method when a third param is passed in', function() {
127-
var t = new TzDate(0, 0, 'Mon Sep 3 2010 17:05:08 GMT+0500 (XYZ)');
128-
expect(t.toString()).toBe('Mon Sep 3 2010 17:05:08 GMT+0500 (XYZ)');
129-
});
130-
131-
132126
it('should throw error when no third param but toString called', function() {
133127
expect(function() { new TzDate(0,0).toString(); }).
134128
toThrow('Method \'toString\' is not implemented in the TzDate mock');

0 commit comments

Comments
 (0)