Skip to content

Commit

Permalink
fix(calendar):fix model's initialization
Browse files Browse the repository at this point in the history
Fix #122
  • Loading branch information
fetrarij committed Apr 2, 2019
1 parent d89333c commit e22e741
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions src/daterangepicker/daterangepicker.component.ts
Expand Up @@ -141,7 +141,7 @@ export class DaterangepickerComponent implements OnInit {
}

ngOnInit() {
this.locale = {...this._localeService.config, ...this.locale};
this._buildLocale();
const daysOfWeek = [...this.locale.daysOfWeek];
if (this.locale.firstDay != 0) {
var iterator = this.locale.firstDay;
Expand All @@ -156,13 +156,7 @@ export class DaterangepickerComponent implements OnInit {
this._old.start = this.startDate.clone();
this._old.end = this.endDate.clone();
}
if (!this.locale.format) {
if (this.timePicker) {
this.locale.format = moment.localeData().longDateFormat('lll');
} else {
this.locale.format = moment.localeData().longDateFormat('L');
}
}

this.updateMonthsInView();
this.renderCalendar(SideEnum.left);
this.renderCalendar(SideEnum.right);
Expand Down Expand Up @@ -625,6 +619,9 @@ export class DaterangepickerComponent implements OnInit {
* this should calculate the label
*/
calculateChosenLabel () {
if (!this.locale || !this.locale.separator) {
this._buildLocale();
}
let customRange = true;
let i = 0;
if (this.rangesArray.length > 0) {
Expand Down Expand Up @@ -1047,6 +1044,19 @@ export class DaterangepickerComponent implements OnInit {
var second = this.timePickerSeconds ? parseInt(this.timepickerVariables[side].selectedSecond, 10) : 0;
return date.clone().hour(hour).minute(minute).second(second);
}
/**
* build the locale config
*/
private _buildLocale() {
this.locale = {...this._localeService.config, ...this.locale};
if (!this.locale.format) {
if (this.timePicker) {
this.locale.format = moment.localeData().longDateFormat('lll');
} else {
this.locale.format = moment.localeData().longDateFormat('L');
}
}
}
private _buildCells(calendar, side: SideEnum) {
for (let row = 0; row < 6; row++) {
this.calendarVariables[side].classes[row] = {};
Expand Down

0 comments on commit e22e741

Please sign in to comment.