Skip to content

Commit 530287d

Browse files
authored
refactor(material-luxon-adapter): clean up unsupported browser workarounds (#23399)
Cleans up some code that is no longer necessary now that we don't support IE and Edge.
1 parent ab6e12f commit 530287d

File tree

2 files changed

+6
-45
lines changed

2 files changed

+6
-45
lines changed

src/material-luxon-adapter/adapter/luxon-date-adapter.spec.ts

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@ const JAN = 1, FEB = 2, MAR = 3, DEC = 12;
1818
describe('LuxonDateAdapter', () => {
1919
let adapter: DateAdapter<DateTime>;
2020

21-
if (!isSupported()) {
22-
it('should pass', () => expect(1).toBe(1));
23-
return;
24-
}
25-
2621
beforeEach(waitForAsync(() => {
2722
TestBed.configureTestingModule({
2823
imports: [LuxonDateModule]
@@ -205,11 +200,11 @@ describe('LuxonDateAdapter', () => {
205200
it('should format with a different locale', () => {
206201
let date = adapter.format(DateTime.local(2017, JAN, 2), 'DD');
207202

208-
expect(stripDirectionalityCharacters(date)).toEqual('Jan 2, 2017');
203+
expect(date).toEqual('Jan 2, 2017');
209204
adapter.setLocale('da-DK');
210205

211206
date = adapter.format(DateTime.local(2017, JAN, 2), 'DD');
212-
expect(stripDirectionalityCharacters(date)).toEqual('2. jan. 2017');
207+
expect(date).toEqual('2. jan. 2017');
213208
});
214209

215210
it('should throw when attempting to format invalid date', () => {
@@ -377,11 +372,6 @@ describe('LuxonDateAdapter', () => {
377372
describe('LuxonDateAdapter with MAT_DATE_LOCALE override', () => {
378373
let adapter: DateAdapter<DateTime>;
379374

380-
if (!isSupported()) {
381-
it('should pass', () => expect(1).toBe(1));
382-
return;
383-
}
384-
385375
beforeEach(waitForAsync(() => {
386376
TestBed.configureTestingModule({
387377
imports: [LuxonDateModule],
@@ -393,18 +383,13 @@ describe('LuxonDateAdapter with MAT_DATE_LOCALE override', () => {
393383

394384
it('should take the default locale id from the MAT_DATE_LOCALE injection token', () => {
395385
const date = adapter.format(DateTime.local(2017, JAN, 2), 'DD');
396-
expect(stripDirectionalityCharacters(date)).toEqual('2. jan. 2017');
386+
expect(date).toEqual('2. jan. 2017');
397387
});
398388
});
399389

400390
describe('LuxonDateAdapter with LOCALE_ID override', () => {
401391
let adapter: DateAdapter<DateTime>;
402392

403-
if (!isSupported()) {
404-
it('should pass', () => expect(1).toBe(1));
405-
return;
406-
}
407-
408393
beforeEach(waitForAsync(() => {
409394
TestBed.configureTestingModule({
410395
imports: [LuxonDateModule],
@@ -416,20 +401,13 @@ describe('LuxonDateAdapter with LOCALE_ID override', () => {
416401

417402
it('should take the default locale id from the LOCALE_ID injection token', () => {
418403
const date = adapter.format(DateTime.local(2017, JAN, 2), 'DD');
419-
420-
// Some browsers add extra invisible characters that we should strip before asserting.
421-
expect(stripDirectionalityCharacters(date)).toEqual('2 janv. 2017');
404+
expect(date).toEqual('2 janv. 2017');
422405
});
423406
});
424407

425408
describe('LuxonDateAdapter with MAT_LUXON_DATE_ADAPTER_OPTIONS override', () => {
426409
let adapter: DateAdapter<DateTime>;
427410

428-
if (!isSupported()) {
429-
it('should pass', () => expect(1).toBe(1));
430-
return;
431-
}
432-
433411
beforeEach(waitForAsync(() => {
434412
TestBed.configureTestingModule({
435413
imports: [LuxonDateModule],
@@ -467,16 +445,6 @@ describe('LuxonDateAdapter with MAT_LUXON_DATE_ADAPTER_OPTIONS override', () =>
467445

468446
});
469447

470-
471-
function isSupported(): boolean {
472-
// As of version 2.0.0 Luxon doesn't support any version of IE so we have to skip the tests there.
473-
return typeof navigator !== 'undefined' && !(/(msie|trident|edge)/i.test(navigator.userAgent));
474-
}
475-
476-
function stripDirectionalityCharacters(str: string) {
477-
return str.replace(/[\u200e\u200f]/g, '');
478-
}
479-
480448
function assertValidDate(adapter: DateAdapter<DateTime>, d: DateTime | null, valid: boolean) {
481449
expect(adapter.isDateInstance(d)).not
482450
.withContext(`Expected ${d} to be a date instance`).toBeNull();

src/material-luxon-adapter/adapter/luxon-date-adapter.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,8 @@ export class LuxonDateAdapter extends DateAdapter<LuxonDateTime> {
8888
// functionality so we have to fall back to the Intl API.
8989
const dtf = new Intl.DateTimeFormat(this.locale, {day: 'numeric', timeZone: 'utc'});
9090

91-
return range(31, i => {
92-
// Format a UTC date in order to avoid DST issues.
93-
const date = LuxonDateTime.utc(2017, 1, i + 1).toJSDate();
94-
95-
// Strip out unicode LTR and RTL characters. Edge and IE insert these into formatted
96-
// dates while other browsers do not. We remove them to make output consistent and
97-
// because they interfere with date parsing.
98-
return dtf.format(date).replace(/[\u200e\u200f]/g, '');
99-
});
91+
// Format a UTC date in order to avoid DST issues.
92+
return range(31, i => dtf.format(LuxonDateTime.utc(2017, 1, i + 1).toJSDate()));
10093
}
10194

10295
getDayOfWeekNames(style: 'long' | 'short' | 'narrow'): string[] {

0 commit comments

Comments
 (0)