Skip to content

Commit afd1112

Browse files
committed
Split in half if there is no separator
1 parent 6872212 commit afd1112

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

src/components/Input.tsx

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,26 @@ const Input: React.FC<Props> = (e: Props) => {
7777
}
7878
} else {
7979
const parsed = inputValue.split(separator);
80+
81+
let startDate = null;
82+
let endDate = null;
83+
8084
if (parsed.length === 2) {
81-
const startDate = parseFormattedDate(parsed[0], displayFormat);
82-
const endDate = parseFormattedDate(parsed[1], displayFormat);
83-
84-
if (
85-
dateIsValid(startDate.toDate()) &&
86-
dateIsValid(endDate.toDate()) &&
87-
startDate.isBefore(endDate)
88-
) {
89-
dates.push(startDate.format(DATE_FORMAT));
90-
dates.push(endDate.format(DATE_FORMAT));
91-
}
85+
startDate = parseFormattedDate(parsed[0], displayFormat);
86+
endDate = parseFormattedDate(parsed[1], displayFormat);
9287
} else {
93-
// TODO: Handle the case where there is separator in the date format or no separator at all
88+
const middle = Math.floor(inputValue.length / 2);
89+
startDate = parseFormattedDate(inputValue.slice(0, middle), displayFormat);
90+
endDate = parseFormattedDate(inputValue.slice(middle), displayFormat);
91+
}
92+
93+
if (
94+
dateIsValid(startDate.toDate()) &&
95+
dateIsValid(endDate.toDate()) &&
96+
startDate.isBefore(endDate)
97+
) {
98+
dates.push(startDate.format(DATE_FORMAT));
99+
dates.push(endDate.format(DATE_FORMAT));
94100
}
95101
}
96102

0 commit comments

Comments
 (0)