Skip to content

Commit 468fae0

Browse files
committed
feat(calendar): Add start of week implementation and update locale based on new one.
1 parent 4db5f2a commit 468fae0

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

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

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@ import { WEEKDAYS, IFormattingOptions, IFormattingViews, IViewDateChangeEventArg
33
import { ControlValueAccessor } from '@angular/forms';
44
import { DateRangeDescriptor } from '../core/dates';
55
import { noop, Subject } from 'rxjs';
6-
import { isDate, isEqual, PlatformUtil } from '../core/utils';
6+
import { getLocaleFirstDayOfWeek, isDate, isEqual, PlatformUtil } from '../core/utils';
77
import { CalendarResourceStringsEN, ICalendarResourceStrings } from '../core/i18n/calendar-resources';
88
import { DateTimeUtil } from '../date-common/util/date-time.util';
9-
import { getLocaleFirstDayOfWeek } from "@angular/common";
109
import { getCurrentResourceStrings } from '../core/i18n/resources';
1110
import { KeyboardNavigationService } from './calendar.services';
1211
import { getYearRange, isDateInRanges } from './common/helpers';
1312
import { CalendarDay } from './common/model';
14-
import { getI18nManager } from 'igniteui-i18n-core';
13+
import { getCurrentI18n, getI18nManager, ResourceChangeEventArgs } from 'igniteui-i18n-core';
1514

1615
/** @hidden @internal */
1716
@Directive({
@@ -290,13 +289,6 @@ export class IgxCalendarBaseDirective implements ControlValueAccessor {
290289
public set locale(value: string) {
291290
this._locale = value;
292291

293-
// if value is not a valid BCP 47 tag, set it back to _localeId
294-
try {
295-
getLocaleFirstDayOfWeek(this._locale);
296-
} catch (e) {
297-
this._locale = this._localeId;
298-
}
299-
300292
// changing locale runtime needs to update the `weekStart` too, if `weekStart` is not explicitly set
301293
if (!this.weekStart) {
302294
this.weekStart = getLocaleFirstDayOfWeek(this._locale);
@@ -657,11 +649,12 @@ export class IgxCalendarBaseDirective implements ControlValueAccessor {
657649
protected keyboardNavigation?: KeyboardNavigationService,
658650
protected cdr?: ChangeDetectorRef,
659651
) {
660-
this.locale = _localeId;
652+
this.locale = getCurrentI18n() || _localeId;
661653
this.viewDate = this.viewDate ? this.viewDate : new Date();
662654
this.initFormatters();
663655

664-
getI18nManager().onResourceChange(() => {
656+
getI18nManager().onResourceChange((args: ResourceChangeEventArgs) => {
657+
this.locale = args.newLocale;
665658
this._resourceStrings = getCurrentResourceStrings(CalendarResourceStringsEN, false);
666659
});
667660
}

projects/igniteui-angular/src/lib/core/utils.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { formatDate as _formatDate, getLocaleCurrencyCode, isPlatformBrowser } from '@angular/common';
1+
import { formatDate as _formatDate, getLocaleCurrencyCode, getLocaleFirstDayOfWeek as ngGetLocaleFirstDayOfWeek, isPlatformBrowser } from '@angular/common';
22
import { Inject, Injectable, InjectionToken, PLATFORM_ID, inject } from '@angular/core';
33
import { mergeWith } from 'lodash-es';
44
import { NEVER, Observable } from 'rxjs';
@@ -681,6 +681,13 @@ export function getCurrencySymbol(currencyCode: string, currencyDisplay?: keyof
681681
return getI18nManager().getCurrencySymbol(currencyCode, currencyDisplay, locale);
682682
}
683683

684+
export function getLocaleFirstDayOfWeek(locale?: string) {
685+
try {
686+
return ngGetLocaleFirstDayOfWeek(locale);
687+
} catch {}
688+
return getI18nManager().getFirstDayOfWeek(locale);
689+
}
690+
684691
/** Converts pixel values to their rem counterparts for a base value */
685692
export const rem = (value: number | string) => {
686693
const base = parseFloat(globalThis.window?.getComputedStyle(globalThis.document?.documentElement).getPropertyValue('--ig-base-font-size'))

0 commit comments

Comments
 (0)