Skip to content

Commit 29c6010

Browse files
committed
chore(*): resolving review comments
1 parent ced5f9e commit 29c6010

File tree

6 files changed

+68
-33
lines changed

6 files changed

+68
-33
lines changed

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

+16-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Input, Output, EventEmitter, Directive } from '@angular/core';
1+
import { Input, Output, EventEmitter, Directive, Inject, LOCALE_ID } from '@angular/core';
22
import { WEEKDAYS, Calendar, isDateInRanges, IFormattingOptions, IFormattingViews } from './calendar';
33
import { ControlValueAccessor } from '@angular/forms';
44
import { DateRangeDescriptor } from '../core/dates';
@@ -163,7 +163,7 @@ export class IgxCalendarBaseDirective implements ControlValueAccessor {
163163
/**
164164
* @hidden
165165
*/
166-
private _locale = 'en';
166+
private _locale;
167167

168168
/**
169169
* @hidden
@@ -240,6 +240,8 @@ export class IgxCalendarBaseDirective implements ControlValueAccessor {
240240
* Can be assigned to a numeric value or to `WEEKDAYS` enum value.
241241
*/
242242
public set weekStart(value: WEEKDAYS | number) {
243+
this._weekStart = value;
244+
243245
this.calendarModel.firstWeekDay = value;
244246
}
245247

@@ -252,16 +254,25 @@ export class IgxCalendarBaseDirective implements ControlValueAccessor {
252254
return this._locale;
253255
}
254256

257+
private _weekStart: number | WEEKDAYS;
258+
255259
/**
256260
* Sets the `locale` of the calendar.
257261
* Expects a valid BCP 47 language tag.
258262
* Default value is `"en"`.
259263
*/
260264
public set locale(value: string) {
261265
this._locale = value;
262-
if (!this.weekStart) {
266+
try {
267+
getLocaleFirstDayOfWeek(this._locale);
268+
} catch (e) {
269+
this._locale = this._localeId;
270+
}
271+
272+
if (this._weekStart === undefined) {
263273
this.calendarModel.firstWeekDay = getLocaleFirstDayOfWeek(this._locale);
264274
}
275+
265276
this.initFormatters();
266277
}
267278

@@ -440,8 +451,9 @@ export class IgxCalendarBaseDirective implements ControlValueAccessor {
440451
/**
441452
* @hidden
442453
*/
443-
constructor(protected platform: PlatformUtil) {
454+
constructor(protected platform: PlatformUtil, @Inject(LOCALE_ID) protected _localeId: any) {
444455
this.calendarModel = new Calendar();
456+
this.locale = _localeId;
445457

446458
this.viewDate = this.viewDate ? this.viewDate : new Date();
447459

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

+6-2
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,16 @@ export class Calendar {
157157

158158
private _firstWeekDay: number | WEEKDAYS;
159159

160-
constructor(firstWeekDay: number | WEEKDAYS = WEEKDAYS.SUNDAY) {
160+
constructor(firstWeekDay: number | WEEKDAYS = undefined) {
161161
this._firstWeekDay = firstWeekDay;
162162
}
163163

164164
public get firstWeekDay(): number {
165-
return this._firstWeekDay % 7;
165+
if (this._firstWeekDay !== undefined) {
166+
return this._firstWeekDay % 7;
167+
}
168+
169+
return this._firstWeekDay;
166170
}
167171

168172
public set firstWeekDay(value: number) {

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import {
88
QueryList,
99
HostBinding,
1010
DoCheck,
11-
OnInit
11+
OnInit,
12+
Inject, LOCALE_ID
1213
} from '@angular/core';
1314
import { ICalendarDate, isDateInRanges } from '../../calendar/calendar';
1415
import { NG_VALUE_ACCESSOR } from '@angular/forms';
@@ -138,9 +139,9 @@ export class IgxDaysViewComponent extends IgxCalendarBaseDirective implements Do
138139
*/
139140
constructor(
140141
public daysNavService: IgxDaysViewNavigationService,
141-
protected platform: PlatformUtil
142+
protected platform: PlatformUtil, @Inject(LOCALE_ID) protected _localeId: any
142143
) {
143-
super(platform);
144+
super(platform, _localeId);
144145
}
145146

146147
/**

projects/igniteui-angular/src/lib/date-common/picker-base.directive.ts

+28-1
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,15 @@ import { IgxInputGroupType, IGX_INPUT_GROUP_TYPE } from '../input-group/public_a
1414
import { OverlaySettings } from '../services/overlay/utilities';
1515
import { IgxPickerToggleComponent } from './picker-icons.common';
1616
import { PickerInteractionMode } from './types';
17+
import { getLocaleFirstDayOfWeek } from "@angular/common";
1718

1819
@Directive()
1920
export abstract class PickerBaseDirective extends DisplayDensityBase implements IToggleView, EditorProvider, AfterViewInit, OnDestroy {
21+
/**
22+
* @hidden
23+
*/
24+
private _locale;
25+
2026
/**
2127
* The editor's input mask.
2228
*
@@ -108,8 +114,29 @@ export abstract class PickerBaseDirective extends DisplayDensityBase implements
108114
* <igx-date-picker locale="jp"></igx-date-picker>
109115
* ```
110116
*/
117+
/**
118+
* Gets the `locale` of the date-picker.
119+
* Default value is `application's LOCALE_ID`.
120+
*/
111121
@Input()
112-
public locale: string;
122+
public get locale(): string {
123+
return this._locale;
124+
}
125+
126+
127+
/**
128+
* Sets the `locale` of the date-picker.
129+
* Expects a valid BCP 47 language tag.
130+
* Default value is `application's LOCALE_ID`.
131+
*/
132+
public set locale(value: string) {
133+
this._locale = value;
134+
try {
135+
getLocaleFirstDayOfWeek(this._locale);
136+
} catch (e) {
137+
this._locale = this._localeId;
138+
}
139+
}
113140

114141
/**
115142
* The container used for the pop-up element.

projects/igniteui-angular/src/lib/date-picker/date-picker.component.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export class IgxDatePickerComponent extends PickerBaseDirective implements Contr
7474
* ```
7575
*/
7676
@Input()
77-
public weekStart: WEEKDAYS | number = WEEKDAYS.SUNDAY;
77+
public weekStart: WEEKDAYS | number;
7878

7979
/**
8080
* Gets/Sets whether the inactive dates will be hidden.
@@ -727,8 +727,12 @@ export class IgxDatePickerComponent extends PickerBaseDirective implements Contr
727727
this._ngControl = this._injector.get<NgControl>(NgControl, null);
728728

729729
this.locale = this.locale || this._localeId;
730-
if (!this.weekStart) {
731-
this.weekStart = getLocaleFirstDayOfWeek(this.locale);
730+
if (this.weekStart == null) {
731+
try {
732+
this.weekStart = getLocaleFirstDayOfWeek(this.locale);
733+
} catch (e) {
734+
this.weekStart = getLocaleFirstDayOfWeek(this._localeId);
735+
}
732736
}
733737
}
734738

projects/igniteui-angular/src/lib/date-range-picker/date-range-picker.component.ts

+7-20
Original file line numberDiff line numberDiff line change
@@ -111,24 +111,7 @@ export class IgxDateRangePickerComponent extends PickerBaseDirective
111111
* ```
112112
*/
113113
@Input()
114-
public weekStart: WEEKDAYS | number = WEEKDAYS.SUNDAY;
115-
116-
/**
117-
* Locale settings used for value formatting and calendar.
118-
*
119-
* @remarks
120-
* Uses Angular's `LOCALE_ID` by default. Affects both input mask and display format if those are not set.
121-
* If a `locale` is set, it must be registered via `registerLocaleData`.
122-
* Please refer to https://angular.io/guide/i18n#i18n-pipes.
123-
* If it is not registered, `Intl` will be used for formatting.
124-
*
125-
* @example
126-
* ```html
127-
* <igx-date-range-picker locale="jp"></igx-date-range-picker>
128-
* ```
129-
*/
130-
@Input()
131-
public locale: string;
114+
public weekStart: WEEKDAYS | number;
132115

133116
/**
134117
* A custom formatter function, applied on the selected or passed in date.
@@ -614,8 +597,12 @@ export class IgxDateRangePickerComponent extends PickerBaseDirective
614597
this._ngControl = this._injector.get<NgControl>(NgControl, null);
615598

616599
this.locale = this.locale || this._localeId;
617-
if (!this.weekStart) {
618-
this.weekStart = getLocaleFirstDayOfWeek(this.locale);
600+
if (this.weekStart === undefined) {
601+
try {
602+
this.weekStart = getLocaleFirstDayOfWeek(this.locale);
603+
} catch (e) {
604+
this.weekStart = getLocaleFirstDayOfWeek(this._localeId);
605+
}
619606
}
620607
}
621608

0 commit comments

Comments
 (0)