Skip to content

Commit

Permalink
Merge pull request #3499 from bettyblocks/fix/datetime-picker-show-de…
Browse files Browse the repository at this point in the history
…fault-value-PAGE-4719

Fix/datetime picker show default value page 4719
  • Loading branch information
ewoutquax authored Oct 8, 2024
2 parents b1f5239 + 079f2c2 commit c95d878
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/components/dateTimePickerInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@
B.defineFunction('Enable', () => setIsDisabled(false));
B.defineFunction('Disable', () => setIsDisabled(true));

const META_API_DATE_FORMAT = 'yyyy-MM-dd';
const META_API_TIME_FORMAT = 'HH:mm:ss';
const DATA_API_DATE_FORMAT = 'yyyy-MM-dd';
const DATA_API_TIME_FORMAT = 'HH:mm:ss';

function getFormat(typeFormat) {
return {
Expand All @@ -107,11 +107,11 @@
break;
}
case 'date': {
parsedDate = DateFns.parse(valueText, META_API_DATE_FORMAT);
parsedDate = DateFns.parse(valueText, DATA_API_DATE_FORMAT);
break;
}
case 'time': {
parsedDate = DateFns.parse(valueText, META_API_TIME_FORMAT);
parsedDate = DateFns.parse(valueText, DATA_API_TIME_FORMAT);
break;
}
default: {
Expand Down Expand Up @@ -199,16 +199,16 @@
};

function convertToValidDate(dateText) {
if (DateFns.isValid(dateText)) {
const parsedValue = DateFns.parse(dateText, dateFormat);
if (dateText) {
const parsedValue = DateFns.parse(dateText, getFormat(typeComponent));
if (isValidDate(parsedValue)) {
return parsedValue;
}
// convert to slashes because it conflicts with the MUI DateTimeCmp
const parsedValueWithSlashes = dateText.replace(/-/g, '/');
return new Date(parsedValueWithSlashes);
}
return '';
return undefined;
}

let DateTimeComponent;
Expand Down

0 comments on commit c95d878

Please sign in to comment.