Topic: Our end-time validation rejects bookings that cross midnight
waveFormDev
pro
asked 1 week ago
A room booking can start late in the evening and finish the next morning. The form has separate start and end dates, but our validator compares only the two time strings and rejects an end time earlier on the clock.
For example, starting at 23:30 and finishing at 00:30 the following day should be valid. Should the comparison use the combined date and time values instead of treating the clock fields separately?
Igor Przybysz
staff
answered 1 week ago
Use the complete offset-qualified values you already have and compare their timestamps. In this example, the end is one hour after the start, even though its displayed clock time is smaller.
Reject missing or invalid values before comparing them, and keep the same validation on the endpoint. Retaining the explicit dates also ensures an end selected on the wrong day is caught.
const startsAt = Date.parse(startValue);
const endsAt = Date.parse(endValue);
const valid = Number.isFinite(startsAt)
&& Number.isFinite(endsAt)
&& endsAt > startsAt;
Igor Przybysz
staff
answered 1 week ago
Compare the complete start and end date-times using the booking's agreed time zone. Clock strings alone cannot distinguish an earlier time on the same day from a valid time on the following day. Validate both selections before comparing their numeric instants.
Use the actual end-date field rather than automatically adding a day whenever the clock time is smaller. That keeps an accidental earlier end date visible as a validation error. Please share your combined-value construction if the overnight case still fails.
https://mdbootstrap.com/docs/standard/forms/datetimepicker/
waveFormDev pro commented 1 week ago
That explains it. The picker values already include their dates and offsets, but our helper extracts HH:mm before checking the range. The two complete values below describe the intended booking.
const startValue = '2026-11-14T23:30:00+01:00';
const endValue = '2026-11-15T00:30:00+01:00';
const valid = endValue.slice(11, 16) > startValue.slice(11, 16);
FREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
Answered
- ForumUser: Pro
- Premium support: No
- Technology: MDB Standard
- MDB Version: MDB5 9.3.0
- Device: Desktop
- Browser: Chrome
- OS: Windows 11
- Provided sample code: No
- Provided link: No