mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-17 07:40:22 +00:00
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.
This commit is contained in:
parent
966cbd4cf8
commit
37b5c5cfe9
5 changed files with 13 additions and 65 deletions
8
src/angular-mocks.js
vendored
8
src/angular-mocks.js
vendored
|
|
@ -439,7 +439,7 @@ function MockLogFactory() {
|
|||
* </pre>
|
||||
*
|
||||
*/
|
||||
function TzDate(offset, timestamp, toStringVal) {
|
||||
function TzDate(offset, timestamp) {
|
||||
if (angular.isString(timestamp)) {
|
||||
var tsStr = timestamp;
|
||||
|
||||
|
|
@ -463,10 +463,6 @@ function TzDate(offset, timestamp, toStringVal) {
|
|||
return this.date.getTime() - this.offsetDiff;
|
||||
};
|
||||
|
||||
this.toString = function() {
|
||||
return toStringVal;
|
||||
};
|
||||
|
||||
this.toLocaleDateString = function() {
|
||||
return this.date.toLocaleDateString();
|
||||
};
|
||||
|
|
@ -537,8 +533,6 @@ function TzDate(offset, timestamp, toStringVal) {
|
|||
'toLocaleTimeString', 'toSource', 'toString', 'toTimeString', 'toUTCString', 'valueOf'];
|
||||
|
||||
angular.forEach(unimplementedMethods, function(methodName) {
|
||||
if (methodName == 'toString' && toStringVal) return;
|
||||
|
||||
self[methodName] = function() {
|
||||
throw {
|
||||
name: "MethodNotImplemented",
|
||||
|
|
|
|||
|
|
@ -215,16 +215,10 @@ function dateStrGetter(name, shortForm) {
|
|||
};
|
||||
}
|
||||
|
||||
function timeZoneGetter(numFormat) {
|
||||
return function(date) {
|
||||
var timeZone;
|
||||
if (numFormat || !(timeZone = GET_TIME_ZONE.exec(date.toString()))) {
|
||||
var offset = date.getTimezoneOffset();
|
||||
return padNumber(offset / 60, 2) + padNumber(Math.abs(offset % 60), 2);
|
||||
}
|
||||
return timeZone[0];
|
||||
};
|
||||
}
|
||||
function timeZoneGetter(date) {
|
||||
var offset = date.getTimezoneOffset();
|
||||
return padNumber(offset / 60, 2) + padNumber(Math.abs(offset % 60), 2);
|
||||
};
|
||||
|
||||
function ampmGetter(date, formats) {
|
||||
return date.getHours() < 12 ? formats.AMPMS[0] : formats.AMPMS[1];
|
||||
|
|
@ -251,8 +245,7 @@ var DATE_FORMATS = {
|
|||
EEEE: dateStrGetter('Day'),
|
||||
EEE: dateStrGetter('Day', true),
|
||||
a: ampmGetter,
|
||||
z: timeZoneGetter(false),
|
||||
Z: timeZoneGetter(true)
|
||||
Z: timeZoneGetter
|
||||
};
|
||||
|
||||
var GET_TIME_ZONE = /[A-Z]{3}(?![+\-])/;
|
||||
|
|
@ -293,13 +286,10 @@ var NUMBER_STRING = /^\d+$/;
|
|||
* * `'s'`: Second in minute (0-59)
|
||||
* * `'a'`: am/pm marker
|
||||
* * `'Z'`: 4 digit (+sign) representation of the timezone offset (-1200-1200)
|
||||
* * `'z'`: short form of current timezone name (e.g. PDT)
|
||||
*
|
||||
* `format` string can also be one of the following predefined
|
||||
* {@link guide/dev_guide.i18n localizable formats}:
|
||||
*
|
||||
* * `'long'`: equivalent to `'MMMM d, y h:mm:ss a z'` for en_US locale
|
||||
* (e.g. September 3, 2010 12:05:08 pm PDT)
|
||||
* * `'medium'`: equivalent to `'MMM d, y h:mm:ss a'` for en_US locale
|
||||
* (e.g. Sep 3, 2010 12:05:08 pm)
|
||||
* * `'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+$/;
|
|||
* * `'longDate'`: equivalent to `'MMMM d, y'` for en_US locale (e.g. September 3, 2010
|
||||
* * `'mediumDate'`: equivalent to `'MMM d, y'` for en_US locale (e.g. Sep 3, 2010)
|
||||
* * `'shortDate'`: equivalent to `'M/d/yy'` for en_US locale (e.g. 9/3/10)
|
||||
* * `'longTime'`: equivalent to `'h:mm:ss a z'` for en_US locale (e.g. 12:05:08 pm PDT)
|
||||
* * `'mediumTime'`: equivalent to `'h:mm:ss a'` for en_US locale (e.g. 12:05:08 pm)
|
||||
* * `'shortTime'`: equivalent to `'h:mm a'` for en_US locale (e.g. 12:05 pm)
|
||||
*
|
||||
|
|
|
|||
|
|
@ -50,14 +50,12 @@ angularServiceInject('$locale', function() {
|
|||
DAY: 'Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday'.split(','),
|
||||
SHORTDAY: 'Sun,Mon,Tue,Wed,Thu,Fri,Sat'.split(','),
|
||||
AMPMS: ['AM','PM'],
|
||||
long: 'MMMM d, y h:mm:ss a z',
|
||||
medium: 'MMM d, y h:mm:ss a',
|
||||
short: 'M/d/yy h:mm a',
|
||||
fullDate: 'EEEE, MMMM d, y',
|
||||
longDate: 'MMMM d, y',
|
||||
mediumDate: 'MMM d, y',
|
||||
shortDate: 'M/d/yy',
|
||||
longTime: 'h:mm:ss a z',
|
||||
mediumTime: 'h:mm:ss a',
|
||||
shortTime: 'h:mm a'
|
||||
}
|
||||
|
|
|
|||
|
|
@ -195,8 +195,6 @@ describe('filter', function() {
|
|||
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
|
||||
|
||||
var context, date;
|
||||
|
||||
|
|
@ -225,16 +223,13 @@ describe('filter', function() {
|
|||
toEqual('10-09-03 07:05:08');
|
||||
|
||||
expect(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(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(date(noon, "yyyy-MM-dd hh=HH:mm:ssaZ")).
|
||||
toEqual('2010-09-03 12=12:05:08pm0500');
|
||||
|
||||
expect(date(timZoneDate, "yyyy-MM-dd hh=HH:mm:ss a z")).
|
||||
toEqual('2010-09-03 12=00:05:08 am XYZ');
|
||||
toEqual('2010-09-03 12=12:05:08PM0500');
|
||||
|
||||
expect(date(noon, "EEE, MMM d, yyyy")).
|
||||
toEqual('Fri, Sep 3, 2010');
|
||||
|
|
@ -258,14 +253,11 @@ describe('filter', function() {
|
|||
|
||||
it('should accept default formats', function() {
|
||||
|
||||
expect(date(timZoneDate, "long")).
|
||||
toEqual('September 3, 2010 12:05:08 am XYZ');
|
||||
|
||||
expect(date(noon, "medium")).
|
||||
toEqual('Sep 3, 2010 12:05:08 pm');
|
||||
toEqual('Sep 3, 2010 12:05:08 PM');
|
||||
|
||||
expect(date(noon, "short")).
|
||||
toEqual('9/3/10 12:05 pm');
|
||||
toEqual('9/3/10 12:05 PM');
|
||||
|
||||
expect(date(noon, "fullDate")).
|
||||
toEqual('Friday, September 3, 2010');
|
||||
|
|
@ -279,32 +271,13 @@ describe('filter', function() {
|
|||
expect(date(noon, "shortDate")).
|
||||
toEqual('9/3/10');
|
||||
|
||||
expect(date(timZoneDate, "longTime")).
|
||||
toEqual('12:05:08 am XYZ');
|
||||
|
||||
expect(date(noon, "mediumTime")).
|
||||
toEqual('12:05:08 pm');
|
||||
toEqual('12:05:08 PM');
|
||||
|
||||
expect(date(noon, "shortTime")).
|
||||
toEqual('12:05 pm');
|
||||
toEqual('12:05 PM');
|
||||
});
|
||||
|
||||
|
||||
it('should parse timezone identifier from various toString values', function() {
|
||||
//chrome and firefox format
|
||||
expect(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(date(new TzDate(+5, '2010-09-03T17:05:08.000Z',
|
||||
'2010-09-03T17:05:08Z'), "z")).toBe('0500');
|
||||
|
||||
//ie 8 format
|
||||
expect(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(date(isoString)).
|
||||
|
|
|
|||
6
test/angular-mocksSpec.js
vendored
6
test/angular-mocksSpec.js
vendored
|
|
@ -123,12 +123,6 @@ describe('mocks', function(){
|
|||
});
|
||||
|
||||
|
||||
it('should fake toString method when a third param is passed in', function() {
|
||||
var t = new TzDate(0, 0, 'Mon Sep 3 2010 17:05:08 GMT+0500 (XYZ)');
|
||||
expect(t.toString()).toBe('Mon Sep 3 2010 17:05:08 GMT+0500 (XYZ)');
|
||||
});
|
||||
|
||||
|
||||
it('should throw error when no third param but toString called', function() {
|
||||
expect(function() { new TzDate(0,0).toString(); }).
|
||||
toThrow('Method \'toString\' is not implemented in the TzDate mock');
|
||||
|
|
|
|||
Loading…
Reference in a new issue