Skip to content

Commit b0313a7

Browse files
committed
fix: fix parsing & formatting of min/max date values in Table columns
Prior to this commit, the parsing of the min & max date values was ignoring the provided dateFormat: Date objects were created with the default JS Date constructor.
1 parent a8347ee commit b0313a7

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/inputs/Table/Table.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,20 @@ const LOADING_STATUS_MAPPING = {
106106
};
107107

108108
const _formatMinMaxDatesInColumns = (col, dateFormat) => {
109-
if (col.type && col.type.indexOf('date') !== -1) {
110-
if (col.minValue) {
111-
col.minValue = DateUtils.format(new Date(col.minValue), dateFormat) || col.minValue;
112-
}
113-
if (col.maxValue) {
114-
col.maxValue = DateUtils.format(new Date(col.maxValue), dateFormat) || col.maxValue;
109+
const formatValueIfNecessary = (value, dateFormat) => {
110+
if (DateUtils.isValid(value, dateFormat)) return value;
111+
if (DateUtils.isValidDate(value)) return DateUtils.format(value, dateFormat);
112+
try {
113+
// Fall back to default Date constructor & format to expected dateFormat
114+
return DateUtils.format(new Date(value), dateFormat);
115+
} catch (error) {
116+
console.error(error);
115117
}
118+
};
119+
120+
if (col.type && col.type.indexOf('date') !== -1) {
121+
if (col.minValue) col.minValue = formatValueIfNecessary(col.minValue, dateFormat);
122+
if (col.maxValue) col.maxValue = formatValueIfNecessary(col.maxValue, dateFormat);
116123
}
117124
};
118125

0 commit comments

Comments
 (0)