mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-3042] Use the custom date adapter from adf-core on Search Date Range widget (#3394)
-fix localization -fix tests -show parse error
This commit is contained in:
committed by
Eugenio Romano
parent
85ff224e26
commit
11bac7e796
@@ -89,7 +89,7 @@ export class MomentDateAdapter extends DateAdapter<Moment> {
|
||||
}
|
||||
|
||||
clone(date: Moment): Moment {
|
||||
return date.clone();
|
||||
return date.clone().locale(this.locale);
|
||||
}
|
||||
|
||||
createDate(year: number, month: number, date: number): Moment {
|
||||
@@ -97,33 +97,37 @@ export class MomentDateAdapter extends DateAdapter<Moment> {
|
||||
}
|
||||
|
||||
today(): Moment {
|
||||
return moment();
|
||||
return moment().locale(this.locale);
|
||||
}
|
||||
|
||||
parse(value: any, parseFormat: any): Moment {
|
||||
let m = moment(value, parseFormat, true);
|
||||
if (!m.isValid()) {
|
||||
m = moment(value, this.overrideDisplyaFormat);
|
||||
}
|
||||
if (m.isValid()) {
|
||||
// if user omits year, it defaults to 2001, so check for that issue.
|
||||
if (m.year() === 2001 && value.indexOf('2001') === -1) {
|
||||
// if 2001 not actually in the value string, change to current year
|
||||
const currentYear = new Date().getFullYear();
|
||||
m.set('year', currentYear);
|
||||
// if date is in the future, set previous year
|
||||
if (m.isAfter(moment())) {
|
||||
m.set('year', currentYear - 1);
|
||||
|
||||
if (value && typeof value === 'string') {
|
||||
let m = moment(value, parseFormat, this.locale, true);
|
||||
if (!m.isValid()) {
|
||||
// use strict parsing because Moment's parser is very forgiving, and this can lead to undesired behavior.
|
||||
m = moment(value, this.overrideDisplyaFormat, this.locale, true);
|
||||
}
|
||||
if (m.isValid()) {
|
||||
// if user omits year, it defaults to 2001, so check for that issue.
|
||||
if (m.year() === 2001 && value.indexOf('2001') === -1) {
|
||||
// if 2001 not actually in the value string, change to current year
|
||||
const currentYear = new Date().getFullYear();
|
||||
m.set('year', currentYear);
|
||||
// if date is in the future, set previous year
|
||||
if (m.isAfter(moment())) {
|
||||
m.set('year', currentYear - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return m;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
return value ? moment(value).locale(this.locale) : null;
|
||||
}
|
||||
|
||||
format(date: Moment, displayFormat: any): string {
|
||||
|
||||
date = this.clone(date);
|
||||
displayFormat = this.overrideDisplyaFormat ? this.overrideDisplyaFormat : displayFormat;
|
||||
|
||||
if (date && date.format) {
|
||||
@@ -150,6 +154,8 @@ export class MomentDateAdapter extends DateAdapter<Moment> {
|
||||
}
|
||||
|
||||
setLocale(locale: any): void {
|
||||
super.setLocale(locale);
|
||||
|
||||
this.localeData = moment.localeData(locale);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user