Skip to content

Commit 8d18c5b

Browse files
author
Matt Lewis
committed
docs(demos): remove Intl usage from demos
1 parent 0b94a31 commit 8d18c5b

File tree

5 files changed

+29
-26
lines changed

5 files changed

+29
-26
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,22 @@
11
import { CalendarDateFormatter, DateFormatterParams } from 'angular-calendar';
2+
import { DatePipe } from '@angular/common';
23

34
export class CustomDateFormatter extends CalendarDateFormatter {
45
// you can override any of the methods defined in the parent class
56

67
public monthViewColumnHeader({ date, locale }: DateFormatterParams): string {
7-
return new Intl.DateTimeFormat(locale, { weekday: 'short' }).format(date);
8+
return new DatePipe(locale).transform(date, 'EEE', locale);
89
}
910

1011
public monthViewTitle({ date, locale }: DateFormatterParams): string {
11-
return new Intl.DateTimeFormat(locale, {
12-
year: 'numeric',
13-
month: 'short'
14-
}).format(date);
12+
return new DatePipe(locale).transform(date, 'MMM y', locale);
1513
}
1614

1715
public weekViewColumnHeader({ date, locale }: DateFormatterParams): string {
18-
return new Intl.DateTimeFormat(locale, { weekday: 'short' }).format(date);
16+
return new DatePipe(locale).transform(date, 'EEE', locale);
1917
}
2018

2119
public dayViewHour({ date, locale }: DateFormatterParams): string {
22-
return new Intl.DateTimeFormat(locale, {
23-
hour: 'numeric',
24-
minute: 'numeric'
25-
}).format(date);
20+
return new DatePipe(locale).transform(date, 'HH:mm', locale);
2621
}
2722
}

demos/demo-modules/i18n/custom-date-formatter.provider.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import { CalendarDateFormatter, DateFormatterParams } from 'angular-calendar';
22
import { getISOWeek } from 'date-fns';
3+
import { DatePipe } from '@angular/common';
34

45
export class CustomDateFormatter extends CalendarDateFormatter {
56
public weekViewTitle({ date, locale }: DateFormatterParams): string {
6-
const year: string = new Intl.DateTimeFormat(locale, {
7-
year: 'numeric'
8-
}).format(date);
7+
const year: string = new DatePipe(locale).transform(date, 'y', locale);
98
const weekNumber: number = getISOWeek(date);
109
return `Semaine ${weekNumber} en ${year}`;
1110
}

demos/demo-modules/i18n/module.ts

+4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1+
import { registerLocaleData } from '@angular/common';
2+
import localeFr from '@angular/common/locales/fr';
13
import { NgModule } from '@angular/core';
24
import { CommonModule } from '@angular/common';
35
import { RouterModule } from '@angular/router';
46
import { CalendarModule } from 'angular-calendar';
57
import { DemoUtilsModule } from '../demo-utils/module';
68
import { DemoComponent } from './component';
79

10+
registerLocaleData(localeFr);
11+
812
@NgModule({
913
imports: [
1014
CommonModule,
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { LOCALE_ID, Inject } from '@angular/core';
22
import { CalendarEventTitleFormatter, CalendarEvent } from 'angular-calendar';
3+
import { DatePipe } from '@angular/common';
34

45
export class CustomEventTitleFormatter extends CalendarEventTitleFormatter {
56
constructor(@Inject(LOCALE_ID) private locale: string) {
@@ -9,23 +10,26 @@ export class CustomEventTitleFormatter extends CalendarEventTitleFormatter {
910
// you can override any of the methods defined in the parent class
1011

1112
month(event: CalendarEvent): string {
12-
return `<b>${new Intl.DateTimeFormat(this.locale, {
13-
hour: 'numeric',
14-
minute: 'numeric'
15-
}).format(event.start)}</b> ${event.title}`;
13+
return `<b>${new DatePipe(this.locale).transform(
14+
event.start,
15+
'h:m a',
16+
this.locale
17+
)}</b> ${event.title}`;
1618
}
1719

1820
week(event: CalendarEvent): string {
19-
return `<b>${new Intl.DateTimeFormat(this.locale, {
20-
hour: 'numeric',
21-
minute: 'numeric'
22-
}).format(event.start)}</b> ${event.title}`;
21+
return `<b>${new DatePipe(this.locale).transform(
22+
event.start,
23+
'h:m a',
24+
this.locale
25+
)}</b> ${event.title}`;
2326
}
2427

2528
day(event: CalendarEvent): string {
26-
return `<b>${new Intl.DateTimeFormat(this.locale, {
27-
hour: 'numeric',
28-
minute: 'numeric'
29-
}).format(event.start)}</b> ${event.title}`;
29+
return `<b>${new DatePipe(this.locale).transform(
30+
event.start,
31+
'h:m a',
32+
this.locale
33+
)}</b> ${event.title}`;
3034
}
3135
}

src/modules/common/calendar-date-formatter.provider.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ import { CalendarAngularDateFormatter } from './calendar-angular-date-formatter.
77
*
88
* ```typescript
99
* import { CalendarDateFormatter, DateFormatterParams } from 'angular-calendar';
10+
* import { DatePipe } from '@angular/common';
1011
*
1112
* class CustomDateFormatter extends CalendarDateFormatter {
1213
*
1314
* public monthViewColumnHeader({date, locale}: DateFormatterParams): string {
14-
* return new Intl.DateTimeFormat(locale, {weekday: 'short'}).format(date); // use short week days
15+
* return new DatePipe(locale).transform(date, 'EEE', locale); // use short week days
1516
* }
1617
*
1718
* }

0 commit comments

Comments
 (0)