Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 4 additions & 36 deletions src/material-luxon-adapter/adapter/luxon-date-adapter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ const JAN = 1, FEB = 2, MAR = 3, DEC = 12;
describe('LuxonDateAdapter', () => {
let adapter: DateAdapter<DateTime>;

if (!isSupported()) {
it('should pass', () => expect(1).toBe(1));
return;
}

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
imports: [LuxonDateModule]
Expand Down Expand Up @@ -205,11 +200,11 @@ describe('LuxonDateAdapter', () => {
it('should format with a different locale', () => {
let date = adapter.format(DateTime.local(2017, JAN, 2), 'DD');

expect(stripDirectionalityCharacters(date)).toEqual('Jan 2, 2017');
expect(date).toEqual('Jan 2, 2017');
adapter.setLocale('da-DK');

date = adapter.format(DateTime.local(2017, JAN, 2), 'DD');
expect(stripDirectionalityCharacters(date)).toEqual('2. jan. 2017');
expect(date).toEqual('2. jan. 2017');
});

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

if (!isSupported()) {
it('should pass', () => expect(1).toBe(1));
return;
}

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
imports: [LuxonDateModule],
Expand All @@ -393,18 +383,13 @@ describe('LuxonDateAdapter with MAT_DATE_LOCALE override', () => {

it('should take the default locale id from the MAT_DATE_LOCALE injection token', () => {
const date = adapter.format(DateTime.local(2017, JAN, 2), 'DD');
expect(stripDirectionalityCharacters(date)).toEqual('2. jan. 2017');
expect(date).toEqual('2. jan. 2017');
});
});

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

if (!isSupported()) {
it('should pass', () => expect(1).toBe(1));
return;
}

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
imports: [LuxonDateModule],
Expand All @@ -416,20 +401,13 @@ describe('LuxonDateAdapter with LOCALE_ID override', () => {

it('should take the default locale id from the LOCALE_ID injection token', () => {
const date = adapter.format(DateTime.local(2017, JAN, 2), 'DD');

// Some browsers add extra invisible characters that we should strip before asserting.
expect(stripDirectionalityCharacters(date)).toEqual('2 janv. 2017');
expect(date).toEqual('2 janv. 2017');
});
});

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

if (!isSupported()) {
it('should pass', () => expect(1).toBe(1));
return;
}

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
imports: [LuxonDateModule],
Expand Down Expand Up @@ -467,16 +445,6 @@ describe('LuxonDateAdapter with MAT_LUXON_DATE_ADAPTER_OPTIONS override', () =>

});


function isSupported(): boolean {
// As of version 2.0.0 Luxon doesn't support any version of IE so we have to skip the tests there.
return typeof navigator !== 'undefined' && !(/(msie|trident|edge)/i.test(navigator.userAgent));
}

function stripDirectionalityCharacters(str: string) {
return str.replace(/[\u200e\u200f]/g, '');
}

function assertValidDate(adapter: DateAdapter<DateTime>, d: DateTime | null, valid: boolean) {
expect(adapter.isDateInstance(d)).not
.withContext(`Expected ${d} to be a date instance`).toBeNull();
Expand Down
11 changes: 2 additions & 9 deletions src/material-luxon-adapter/adapter/luxon-date-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,8 @@ export class LuxonDateAdapter extends DateAdapter<LuxonDateTime> {
// functionality so we have to fall back to the Intl API.
const dtf = new Intl.DateTimeFormat(this.locale, {day: 'numeric', timeZone: 'utc'});

return range(31, i => {
// Format a UTC date in order to avoid DST issues.
const date = LuxonDateTime.utc(2017, 1, i + 1).toJSDate();

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

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