Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix locale customization not being applied when using locale.locale + fix locale custom format not being applied on display label #552

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions demo/src/app/locale/locale.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
[(ngModel)]="selected"
class="form-control"
placeholder="Choose date"
[locale]="{ locale, applyLabel: 'Ack' }" />
[showCustomRangeLabel]="true"
[ranges]="datesRanges"
[alwaysShowCalendars]="true"
[locale]="{ locale, applyLabel: 'Ack', displayFormat: 'YYYY MMM DD', separator: ' :: ' }" />
</div>

</div>
10 changes: 9 additions & 1 deletion demo/src/app/locale/locale.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,16 @@ dayjs.extend(utc);
export class LocaleComponent implements OnInit {
selected: { startDate: dayjs.Dayjs; endDate: dayjs.Dayjs };
locale = fr;
constructor() {}
datesRanges: any = {
['Today']: [dayjs(), dayjs()],
['Yesterday']: [dayjs().subtract(1, 'days'), dayjs().subtract(1, 'days')],
['Last 7 days']: [dayjs().subtract(6, 'days'), dayjs()],
['Last 30 days']: [dayjs().subtract(29, 'days'), dayjs()],
['This month']: [dayjs().startOf('month'), dayjs().endOf('month')],
['Last month']: [dayjs().subtract(1, 'month').startOf('month'), dayjs().subtract(1, 'month').endOf('month')],
};

constructor() {}

ngOnInit(): void {}
}
25 changes: 21 additions & 4 deletions src/daterangepicker/daterangepicker.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,16 @@ export class DaterangepickerComponent implements OnInit, OnChanges {

@Input() set locale(value: LocaleConfig) {
this.localeHolder = { ...this.localeHolderService.config, ...value };

if (value.locale) {
this.localeHolder = this.localeHolderService.configWithLocale(value.locale);
const tempValue = { ...value }; // make copy of value
// remove fields being applied from value.locale
delete tempValue.daysOfWeek;
delete tempValue.monthNames;
delete tempValue.firstDay;

// combine config with locale and customized LocaleConfig
this.localeHolder = { ...this.localeHolderService.configWithLocale(value.locale), ...tempValue };
}
}

Expand Down Expand Up @@ -844,7 +852,7 @@ export class DaterangepickerComponent implements OnInit, OnChanges {
return;
}
if (this.startDate) {
// we want to stay on whatever months are in view if date range is set and both calendar sides have a month already. e.g. when
// we want to stay on whatever months are in view if date range is set and both calendar sides have a month already. e.g. when
// user clicks on the end date, we want to stay on current month in view
if (this.leftCalendar.month && this.rightCalendar.month) {
return;
Expand Down Expand Up @@ -897,11 +905,20 @@ export class DaterangepickerComponent implements OnInit, OnChanges {
) {
this.chosenLabel = this.chosenRange;
} else {
this.chosenLabel = this.startDate.format(format) + this.locale.separator + this.endDate.format(format);
const formattedStartDate = this.localeHolder.locale
? this.startDate.locale(this.localeHolder.locale).format(format)
: this.startDate.format(format);
const formattedEndDate = this.localeHolder.locale
? this.endDate.locale(this.localeHolder.locale).format(format)
: this.endDate.format(format);

this.chosenLabel = formattedStartDate + this.locale.separator + formattedEndDate;
}
}
} else if (this.autoUpdateInput) {
this.chosenLabel = this.startDate.format(format);
this.chosenLabel = this.localeHolder.locale
? this.startDate.locale(this.localeHolder.locale).format(format)
: this.startDate.format(format);
}
}

Expand Down