@@ -51,25 +51,20 @@ const DateTimePicker = ({ value, onChange, onBlur, id, onlyFuture, onlyToday, is
|
||||
if (!v) return;
|
||||
|
||||
const upperV = normalizeDateTimeString(v);
|
||||
console.log(upperV);
|
||||
let _a;
|
||||
let parsedDate;
|
||||
|
||||
let formatTemp;
|
||||
for (const format of isDateOnly ? dateFormats : dateTimeFormats) {
|
||||
_a = dayjs(upperV, format);
|
||||
formatTemp = format;
|
||||
if (_a.isValid()) break;
|
||||
parsedDate = dayjs(upperV, format);
|
||||
if (parsedDate.isValid()) break;
|
||||
}
|
||||
console.log("HIT FORMAT");
|
||||
console.log(formatTemp);
|
||||
|
||||
if (_a && _a.isValid()) {
|
||||
if (parsedDate && parsedDate.isValid()) {
|
||||
if (isDateOnly) {
|
||||
_a = _a.startOf("day");
|
||||
parsedDate = parsedDate.startOf("day");
|
||||
}
|
||||
|
||||
if (value && value.isValid && value.isValid()) {
|
||||
_a.set({
|
||||
parsedDate = parsedDate.set({
|
||||
hours: value.hours(),
|
||||
minutes: value.minutes(),
|
||||
seconds: value.seconds(),
|
||||
@@ -78,13 +73,13 @@ const DateTimePicker = ({ value, onChange, onBlur, id, onlyFuture, onlyToday, is
|
||||
}
|
||||
|
||||
if (onlyFuture) {
|
||||
if (dayjs().subtract(1, "day").isBefore(_a)) {
|
||||
onChange(_a);
|
||||
if (dayjs().subtract(1, "day").isBefore(parsedDate)) {
|
||||
onChange(parsedDate);
|
||||
} else {
|
||||
onChange(dayjs().startOf("day"));
|
||||
}
|
||||
} else {
|
||||
onChange(_a);
|
||||
onChange(parsedDate);
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -96,9 +91,11 @@ const DateTimePicker = ({ value, onChange, onBlur, id, onlyFuture, onlyToday, is
|
||||
setIsManualInput(true);
|
||||
|
||||
if (e.key.toLowerCase() === "t" && onChange) {
|
||||
e.preventDefault();
|
||||
setIsManualInput(false);
|
||||
onChange(dayjs());
|
||||
} else if (e.key.toLowerCase() === "enter") {
|
||||
e.preventDefault();
|
||||
handleBlur(e);
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user