I am coding a reservation website and trying to code the logic for the intervals myself. The code is supposed to compare the "since" and "until" dates, and if the "since" selected comes after "before", before should automatically set to "since" plus one day. Although it seems to work when both dates are on the same month (like "before==2020-12-12", "after==2020-20-11") if I try to compare something like this (like "before==2021-01-12", "after==2020-20-11") it won't work.
Here goes the code, and thanks a lot.
the input looks like this
//2021-01-13T00:00:00-03:00
handleDateChange = (limit, value) => {
if (limit === "since") {
if (this.state.until === "") {
let until = new Date(value);
this.setState({
[limit]: new Date(value),
until: new Date(until.setDate(new Date(value).getDate() + 1))
});
} else if (
new Date(value).valueOf() > new Date(this.state.until).valueOf()
) {
console.log(value.valueOf());
console.log(this.state.until.valueOf());
console.log(new Date(this.state.until).valueOf());
this.setState({
[limit]: new Date(value),
until: new Date(
this.state.until.setDate(new Date(value).getDate() + 1)
)
});
}
} else if (limit === "until" && this.state.since === "") {
this.setState({
until: new Date(value),
since: new Date()
});
} else {
this.setState({
...this.state,
[limit]: new Date(value)
});
}
};```