Skip to content

Commit

Permalink
docs(demos): remove Intl usage from demos
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Lewis committed Dec 27, 2017
1 parent 0b94a31 commit 8d18c5b
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
import { CalendarDateFormatter, DateFormatterParams } from 'angular-calendar';
import { DatePipe } from '@angular/common';

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

public monthViewColumnHeader({ date, locale }: DateFormatterParams): string {
return new Intl.DateTimeFormat(locale, { weekday: 'short' }).format(date);
return new DatePipe(locale).transform(date, 'EEE', locale);
}

public monthViewTitle({ date, locale }: DateFormatterParams): string {
return new Intl.DateTimeFormat(locale, {
year: 'numeric',
month: 'short'
}).format(date);
return new DatePipe(locale).transform(date, 'MMM y', locale);
}

public weekViewColumnHeader({ date, locale }: DateFormatterParams): string {
return new Intl.DateTimeFormat(locale, { weekday: 'short' }).format(date);
return new DatePipe(locale).transform(date, 'EEE', locale);
}

public dayViewHour({ date, locale }: DateFormatterParams): string {
return new Intl.DateTimeFormat(locale, {
hour: 'numeric',
minute: 'numeric'
}).format(date);
return new DatePipe(locale).transform(date, 'HH:mm', locale);
}
}
5 changes: 2 additions & 3 deletions demos/demo-modules/i18n/custom-date-formatter.provider.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { CalendarDateFormatter, DateFormatterParams } from 'angular-calendar';
import { getISOWeek } from 'date-fns';
import { DatePipe } from '@angular/common';

export class CustomDateFormatter extends CalendarDateFormatter {
public weekViewTitle({ date, locale }: DateFormatterParams): string {
const year: string = new Intl.DateTimeFormat(locale, {
year: 'numeric'
}).format(date);
const year: string = new DatePipe(locale).transform(date, 'y', locale);
const weekNumber: number = getISOWeek(date);
return `Semaine ${weekNumber} en ${year}`;
}
Expand Down
4 changes: 4 additions & 0 deletions demos/demo-modules/i18n/module.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { registerLocaleData } from '@angular/common';
import localeFr from '@angular/common/locales/fr';
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { RouterModule } from '@angular/router';
import { CalendarModule } from 'angular-calendar';
import { DemoUtilsModule } from '../demo-utils/module';
import { DemoComponent } from './component';

registerLocaleData(localeFr);

@NgModule({
imports: [
CommonModule,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { LOCALE_ID, Inject } from '@angular/core';
import { CalendarEventTitleFormatter, CalendarEvent } from 'angular-calendar';
import { DatePipe } from '@angular/common';

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

month(event: CalendarEvent): string {
return `<b>${new Intl.DateTimeFormat(this.locale, {
hour: 'numeric',
minute: 'numeric'
}).format(event.start)}</b> ${event.title}`;
return `<b>${new DatePipe(this.locale).transform(
event.start,
'h:m a',
this.locale
)}</b> ${event.title}`;
}

week(event: CalendarEvent): string {
return `<b>${new Intl.DateTimeFormat(this.locale, {
hour: 'numeric',
minute: 'numeric'
}).format(event.start)}</b> ${event.title}`;
return `<b>${new DatePipe(this.locale).transform(
event.start,
'h:m a',
this.locale
)}</b> ${event.title}`;
}

day(event: CalendarEvent): string {
return `<b>${new Intl.DateTimeFormat(this.locale, {
hour: 'numeric',
minute: 'numeric'
}).format(event.start)}</b> ${event.title}`;
return `<b>${new DatePipe(this.locale).transform(
event.start,
'h:m a',
this.locale
)}</b> ${event.title}`;
}
}
3 changes: 2 additions & 1 deletion src/modules/common/calendar-date-formatter.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import { CalendarAngularDateFormatter } from './calendar-angular-date-formatter.
*
* ```typescript
* import { CalendarDateFormatter, DateFormatterParams } from 'angular-calendar';
* import { DatePipe } from '@angular/common';
*
* class CustomDateFormatter extends CalendarDateFormatter {
*
* public monthViewColumnHeader({date, locale}: DateFormatterParams): string {
* return new Intl.DateTimeFormat(locale, {weekday: 'short'}).format(date); // use short week days
* return new DatePipe(locale).transform(date, 'EEE', locale); // use short week days
* }
*
* }
Expand Down

0 comments on commit 8d18c5b

Please sign in to comment.