Skip to content

Commit 4d80504

Browse files
committed
refactor(calendar): Defer any creation of Intl.DateTimeFormat to new locale manager.
1 parent fe690f4 commit 4d80504

File tree

5 files changed

+11
-8
lines changed

5 files changed

+11
-8
lines changed

projects/igniteui-angular/src/lib/calendar/calendar.component.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import { CalendarDay } from './common/model';
3434
import { IgxCalendarBaseDirective } from './calendar-base';
3535
import { KeyboardNavigationService } from './calendar.services';
3636
import { IgxDateFormatterPipe } from '../grids/common/pipes';
37+
import { getI18nManager } from 'igniteui-i18n-core';
3738

3839
let NEXT_ID = 0;
3940

@@ -879,12 +880,12 @@ export class IgxCalendarComponent extends IgxCalendarBaseDirective implements Af
879880
*/
880881
protected getFormattedDate(): { weekday: string; monthday: string } {
881882
const date = this.headerDate;
882-
const monthFormatter = new Intl.DateTimeFormat(this.locale, { month: 'short', day: 'numeric' })
883-
const dayFormatter = new Intl.DateTimeFormat(this.locale, { weekday: 'short' })
883+
const monthFormatted = getI18nManager().formatDateTime(date, this.locale, { month: 'short', day: 'numeric' });
884+
const dayFormatted = getI18nManager().formatDateTime(date, this.locale,{ weekday: 'short' });
884885

885886
return {
886-
monthday: monthFormatter.format(date),
887-
weekday: dayFormatter.format(date),
887+
monthday: monthFormatted,
888+
weekday: dayFormatted,
888889
};
889890
}
890891

projects/igniteui-angular/src/lib/calendar/common/helpers.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
} from "./model";
88
import { DateRangeDescriptor, DateRangeType } from "./types";
99
import { first, last, modulo } from "../../core/utils";
10+
import { getI18nManager } from 'igniteui-i18n-core';
1011

1112
interface IFormattedParts {
1213
value: string;
@@ -171,7 +172,7 @@ export function formatToParts(
171172
options: Intl.DateTimeFormatOptions,
172173
parts: string[],
173174
): Record<string, any> {
174-
const formatter = new Intl.DateTimeFormat(locale, options);
175+
const formatter = getI18nManager().getDateFormatter(locale, options);
175176
const result: Record<string, any> = {
176177
date,
177178
full: formatter.format(date),

projects/igniteui-angular/src/lib/calendar/days-view/days-view.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
isDateInRanges,
3232
} from "../common/helpers";
3333
import { CalendarDay } from '../common/model';
34+
import { getI18nManager } from 'igniteui-i18n-core';
3435

3536
let NEXT_ID = 0;
3637

@@ -399,7 +400,7 @@ export class IgxDaysViewComponent extends IgxCalendarBaseDirective {
399400
*/
400401
public get weekHeaderLabels(): {long: string, formatted: string}[] {
401402
const weekdays = [];
402-
const rawFormatter = new Intl.DateTimeFormat(this.locale, { weekday: 'long' });
403+
const rawFormatter = getI18nManager().getDateFormatter(this.locale, { weekday: 'long' });
403404

404405
for (const day of this.monthWeeks.at(0)) {
405406
weekdays.push({

projects/igniteui-angular/src/lib/calendar/months-view/months-view.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ export class IgxMonthsViewComponent extends IgxCalendarViewDirective implements
157157
* @hidden
158158
*/
159159
public formattedMonth(value: Date): { long: string; formatted: string } {
160-
const rawFormatter = new Intl.DateTimeFormat(this.locale, {
160+
const rawFormatter = getI18nManager().getDateFormatter(this.locale, {
161161
month: "long",
162162
year: "numeric",
163163
});

projects/igniteui-angular/src/lib/calendar/years-view/years-view.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ export class IgxYearsViewComponent extends IgxCalendarViewDirective implements C
130130
* @hidden
131131
*/
132132
public formattedYear(value: Date): {long: string, formatted: string} {
133-
const rawFormatter = new Intl.DateTimeFormat(this.locale, { year: 'numeric' });
133+
const rawFormatter = getI18nManager().getDateFormatter(this.locale, { year: 'numeric' });
134134

135135
if (this.formatView) {
136136
return {

0 commit comments

Comments
 (0)