Skip to content

Commit 57273f3

Browse files
authored
refactor(material/core): cleanup unsupported browser workarounds (#23390)
Cleans up the code needed to support IE, Edge and Safari 9 since we don't support either of them as of version 13.
1 parent 692ebaf commit 57273f3

File tree

3 files changed

+55
-219
lines changed

3 files changed

+55
-219
lines changed

src/material/core/datetime/native-date-adapter.spec.ts

Lines changed: 32 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
import {Platform} from '@angular/cdk/platform';
21
import {LOCALE_ID} from '@angular/core';
32
import {waitForAsync, inject, TestBed} from '@angular/core/testing';
43
import {DEC, FEB, JAN, MAR} from '../../testing';
54
import {DateAdapter, MAT_DATE_LOCALE, NativeDateAdapter, NativeDateModule} from './index';
65

7-
const SUPPORTS_INTL = typeof Intl != 'undefined';
8-
96

107
describe('NativeDateAdapter', () => {
11-
let platform: Platform;
128
let adapter: NativeDateAdapter;
139
let assertValidDate: (d: Date | null, valid: boolean) => void;
1410

@@ -18,10 +14,8 @@ describe('NativeDateAdapter', () => {
1814
}).compileComponents();
1915
}));
2016

21-
beforeEach(inject([DateAdapter, Platform],
22-
(dateAdapter: NativeDateAdapter, _platform: Platform) => {
17+
beforeEach(inject([DateAdapter], (dateAdapter: NativeDateAdapter) => {
2318
adapter = dateAdapter;
24-
platform = _platform;
2519

2620
assertValidDate = (d: Date | null, valid: boolean) => {
2721
expect(adapter.isDateInstance(d)).not
@@ -62,30 +56,16 @@ describe('NativeDateAdapter', () => {
6256
});
6357

6458
it('should get narrow month names', () => {
65-
// Edge & IE use same value for short and narrow.
66-
if (platform.EDGE || platform.TRIDENT) {
67-
expect(adapter.getMonthNames('narrow')).toEqual([
68-
'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'
69-
]);
70-
} else {
71-
expect(adapter.getMonthNames('narrow')).toEqual([
72-
'J', 'F', 'M', 'A', 'M', 'J', 'J', 'A', 'S', 'O', 'N', 'D'
73-
]);
74-
}
59+
expect(adapter.getMonthNames('narrow')).toEqual([
60+
'J', 'F', 'M', 'A', 'M', 'J', 'J', 'A', 'S', 'O', 'N', 'D'
61+
]);
7562
});
7663

7764
it('should get month names in a different locale', () => {
7865
adapter.setLocale('ja-JP');
79-
if (SUPPORTS_INTL) {
80-
expect(adapter.getMonthNames('long')).toEqual([
81-
'1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'
82-
]);
83-
} else {
84-
expect(adapter.getMonthNames('long')).toEqual([
85-
'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September',
86-
'October', 'November', 'December'
87-
]);
88-
}
66+
expect(adapter.getMonthNames('long')).toEqual([
67+
'1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'
68+
]);
8969
});
9070

9171
it('should get date names', () => {
@@ -97,18 +77,11 @@ describe('NativeDateAdapter', () => {
9777

9878
it('should get date names in a different locale', () => {
9979
adapter.setLocale('ja-JP');
100-
if (SUPPORTS_INTL) {
101-
expect(adapter.getDateNames()).toEqual([
102-
'1日', '2日', '3日', '4日', '5日', '6日', '7日', '8日', '9日', '10日', '11日', '12日',
103-
'13日', '14日', '15日', '16日', '17日', '18日', '19日', '20日', '21日', '22日', '23日', '24日',
104-
'25日', '26日', '27日', '28日', '29日', '30日', '31日'
105-
]);
106-
} else {
107-
expect(adapter.getDateNames()).toEqual([
108-
'1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17',
109-
'18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31'
110-
]);
111-
}
80+
expect(adapter.getDateNames()).toEqual([
81+
'1日', '2日', '3日', '4日', '5日', '6日', '7日', '8日', '9日', '10日', '11日', '12日',
82+
'13日', '14日', '15日', '16日', '17日', '18日', '19日', '20日', '21日', '22日', '23日', '24日',
83+
'25日', '26日', '27日', '28日', '29日', '30日', '31日'
84+
]);
11285
});
11386

11487
it('should get long day of week names', () => {
@@ -124,29 +97,16 @@ describe('NativeDateAdapter', () => {
12497
});
12598

12699
it('should get narrow day of week names', () => {
127-
// Edge & IE use two-letter narrow days.
128-
if (platform.EDGE || platform.TRIDENT) {
129-
expect(adapter.getDayOfWeekNames('narrow')).toEqual([
130-
'Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'
131-
]);
132-
} else {
133-
expect(adapter.getDayOfWeekNames('narrow')).toEqual([
134-
'S', 'M', 'T', 'W', 'T', 'F', 'S'
135-
]);
136-
}
100+
expect(adapter.getDayOfWeekNames('narrow')).toEqual([
101+
'S', 'M', 'T', 'W', 'T', 'F', 'S'
102+
]);
137103
});
138104

139105
it('should get day of week names in a different locale', () => {
140106
adapter.setLocale('ja-JP');
141-
if (SUPPORTS_INTL) {
142-
expect(adapter.getDayOfWeekNames('long')).toEqual([
143-
'日曜日', '月曜日', '火曜日', '水曜日', '木曜日', '金曜日', '土曜日'
144-
]);
145-
} else {
146-
expect(adapter.getDayOfWeekNames('long')).toEqual([
147-
'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'
148-
]);
149-
}
107+
expect(adapter.getDayOfWeekNames('long')).toEqual([
108+
'日曜日', '月曜日', '火曜日', '水曜日', '木曜日', '金曜日', '土曜日'
109+
]);
150110
});
151111

152112
it('should get year name', () => {
@@ -165,11 +125,7 @@ describe('NativeDateAdapter', () => {
165125

166126
it('should get year name in a different locale', () => {
167127
adapter.setLocale('ja-JP');
168-
if (SUPPORTS_INTL) {
169-
expect(adapter.getYearName(new Date(2017, JAN, 1))).toBe('2017年');
170-
} else {
171-
expect(adapter.getYearName(new Date(2017, JAN, 1))).toBe('2017');
172-
}
128+
expect(adapter.getYearName(new Date(2017, JAN, 1))).toBe('2017年');
173129
});
174130

175131
it('should get first day of week', () => {
@@ -203,15 +159,9 @@ describe('NativeDateAdapter', () => {
203159
return adapter.format(adapter.createDate(year, JAN, 1), {});
204160
};
205161

206-
if (SUPPORTS_INTL) {
207-
expect(createAndFormat(50)).toBe('1/1/50');
208-
expect(createAndFormat(99)).toBe('1/1/99');
209-
expect(createAndFormat(100)).toBe('1/1/100');
210-
} else {
211-
expect(createAndFormat(50)).toBe('Sat Jan 01 0050');
212-
expect(createAndFormat(99)).toBe('Thu Jan 01 0099');
213-
expect(createAndFormat(100)).toBe('Fri Jan 01 0100');
214-
}
162+
expect(createAndFormat(50)).toBe('1/1/50');
163+
expect(createAndFormat(99)).toBe('1/1/99');
164+
expect(createAndFormat(100)).toBe('1/1/100');
215165
});
216166

217167
it("should get today's date", () => {
@@ -244,41 +194,20 @@ describe('NativeDateAdapter', () => {
244194
});
245195

246196
it('should format', () => {
247-
if (SUPPORTS_INTL) {
248-
expect(adapter.format(new Date(2017, JAN, 1), {})).toEqual('1/1/2017');
249-
} else {
250-
expect(adapter.format(new Date(2017, JAN, 1), {})).toEqual('Sun Jan 01 2017');
251-
}
197+
expect(adapter.format(new Date(2017, JAN, 1), {})).toEqual('1/1/2017');
252198
});
253199

254200
it('should format with custom format', () => {
255-
if (SUPPORTS_INTL) {
256-
expect(adapter.format(new Date(2017, JAN, 1), {
257-
year: 'numeric',
258-
month: 'long',
259-
day: 'numeric'
260-
})).toEqual('January 1, 2017');
261-
} else {
262-
expect(adapter.format(new Date(2017, JAN, 1), {
263-
year: 'numeric',
264-
month: 'long',
265-
day: 'numeric'
266-
})).toEqual('Sun Jan 01 2017');
267-
}
201+
expect(adapter.format(new Date(2017, JAN, 1), {
202+
year: 'numeric',
203+
month: 'long',
204+
day: 'numeric'
205+
})).toEqual('January 1, 2017');
268206
});
269207

270208
it('should format with a different locale', () => {
271209
adapter.setLocale('ja-JP');
272-
if (SUPPORTS_INTL) {
273-
// Edge & IE use a different format in Japanese.
274-
if (platform.EDGE || platform.TRIDENT) {
275-
expect(adapter.format(new Date(2017, JAN, 1), {})).toEqual('2017年1月1日');
276-
} else {
277-
expect(adapter.format(new Date(2017, JAN, 1), {})).toEqual('2017/1/1');
278-
}
279-
} else {
280-
expect(adapter.format(new Date(2017, JAN, 1), {})).toEqual('Sun Jan 01 2017');
281-
}
210+
expect(adapter.format(new Date(2017, JAN, 1), {})).toEqual('2017/1/1');
282211
});
283212

284213
it('should throw when attempting to format invalid date', () => {
@@ -352,11 +281,7 @@ describe('NativeDateAdapter', () => {
352281
});
353282

354283
it('should use UTC for formatting by default', () => {
355-
if (SUPPORTS_INTL) {
356-
expect(adapter.format(new Date(1800, 7, 14), {day: 'numeric'})).toBe('14');
357-
} else {
358-
expect(adapter.format(new Date(1800, 7, 14), {day: 'numeric'})).toBe('Thu Aug 14 1800');
359-
}
284+
expect(adapter.format(new Date(1800, 7, 14), {day: 'numeric'})).toBe('14');
360285
});
361286

362287
it('should count today as a valid date instance', () => {
@@ -432,10 +357,7 @@ describe('NativeDateAdapter with MAT_DATE_LOCALE override', () => {
432357
}));
433358

434359
it('should take the default locale id from the MAT_DATE_LOCALE injection token', () => {
435-
const expectedValue = SUPPORTS_INTL ?
436-
['søndag', 'mandag', 'tirsdag', 'onsdag', 'torsdag', 'fredag', 'lørdag'] :
437-
['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
438-
360+
const expectedValue = ['søndag', 'mandag', 'tirsdag', 'onsdag', 'torsdag', 'fredag', 'lørdag'];
439361
expect(adapter.getDayOfWeekNames('long')).toEqual(expectedValue);
440362
});
441363

@@ -456,10 +378,7 @@ describe('NativeDateAdapter with LOCALE_ID override', () => {
456378
}));
457379

458380
it('should cascade locale id from the LOCALE_ID injection token to MAT_DATE_LOCALE', () => {
459-
const expectedValue = SUPPORTS_INTL ?
460-
['søndag', 'mandag', 'tirsdag', 'onsdag', 'torsdag', 'fredag', 'lørdag'] :
461-
['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
462-
381+
const expectedValue = ['søndag', 'mandag', 'tirsdag', 'onsdag', 'torsdag', 'fredag', 'lørdag'];
463382
expect(adapter.getDayOfWeekNames('long')).toEqual(expectedValue);
464383
});
465384
});

0 commit comments

Comments
 (0)