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

FIO-5566: Fixes an issue where deprication warning appears in the console when using Day component with dateFirst setting #5024

Merged
merged 5 commits into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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: 0 additions & 7 deletions src/components/day/Day.js
Original file line number Diff line number Diff line change
Expand Up @@ -516,19 +516,12 @@ export default class DayComponent extends Field {
return this.getDate();
}

normalizeMinMaxDates() {
return [this.component.minDate, this.component.maxDate]
.map(date => date ? date.split('-').reverse().join('/') : date);
}

/**
* Return the raw value.
*
* @returns {Date}
*/
get validationValue() {
[this.component.minDate, this.component.maxDate] = this.dayFirst ? this.normalizeMinMaxDates()
: [this.component.minDate, this.component.maxDate];
return this.dataValue;
}

Expand Down
15 changes: 13 additions & 2 deletions src/components/day/Day.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,20 @@ describe('Day Component', () => {
});
});

it('should normalize min-max dates on dayFirst', () => {
it('Should properly validate min-max dates when dayFirst is checked', (done) => {
Harness.testCreate(DayComponent, comp3).then((component) => {
assert.deepEqual(component.normalizeMinMaxDates(), ['04/02/2020', '09/02/2020']);
component.setValue('01/02/2020');
assert(!component.checkValidity(component.data, true), 'Component should not be valid');

component.setValue('04/01/2021');
assert(!component.checkValidity(component.data, true), 'Component should not be valid');

component.setValue('03/01/2021');
assert(component.checkValidity(component.data, true), 'Component should be valid');

component.setValue('01/03/2020');
assert(component.checkValidity(component.data, true), 'Component should be valid');
done();
});
});

Expand Down
4 changes: 2 additions & 2 deletions src/components/day/fixtures/comp3.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ export default {
'validate': {
'custom': ''
},
'minDate': '2020-02-04',
'maxDate': '2020-02-09',
'minDate': '2020-03-01',
'maxDate': '2021-01-03',
'clearOnHide': true,
'persistent': true,
'protected': false,
Expand Down
8 changes: 7 additions & 1 deletion src/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,13 @@ export function getDateSetting(date) {
return date.isValid() ? date.toDate() : null;
}

let dateSetting = ((typeof date !== 'string') || (date.indexOf('moment(') === -1)) ? moment(date) : null;
let dateSetting = null;
if (typeof date !== 'string') {
dateSetting = moment(date);
}
else if (date.indexOf('moment(') === -1) {
dateSetting = moment(date, 'YYYY-MM-DD');
}
if (dateSetting && dateSetting.isValid()) {
return dateSetting.toDate();
}
Expand Down