12 AM
is considered as next day
timeone = "5/18/2017 01:00 AM"
currenTime = "5/18/2017 05:55 AM"
timetwo = "5/18/2017 12:00 AM"
I see that this condition
fails when the time is 12:00 AM
, how do i handle this
case?
timeone.isBefore(currentTime) => passes
currentTime.isBefore(timetwo) => fails
if (timeone.isBefore(currentTime) && currentTime.isBefore(timetwo)) {
}
Update:
var timeone = moment(time1, 'MM/DD/YYYY hh:mm a');
var timetwo = moment(time2, 'MM/DD/YYYY hh:mm a');
var currentTime = moment(currentTime, 'MM/DD/YYYY hh:mm a');
Also, if you wonder whether tonight's midnight really belong to tonight – or to tomorrow morning: astronomers and the military use a system in which midnight is 0 hours. In that system, tonight's midnight is the first moment of tomorrow. But as for the rest of us – there's no official answer.
"12:00 AM" and "12:00 PM" are technically ambiguous, because AM means "before noon", and PM "after noon". Since noon is neither before nor after noon, and midnight could be considered the end of one day or the start of the next, neither label fits.
However, it's a very common interpretation that 12:00AM means midnight (00:00 in 24-hour notation) and 12:00PM means noon (12:00 in 24-hour notation). Wikipedia has a section on various interpretations.
This is the interpretation your library is using, so "5/18/2017 12:00 AM" = "5/18/2017 00:00", which is clearly before "5/18/2017 05:55 AM".
If your users are consistently expecting the opposite interpretation, you could pre-process the input to swap values around. However, it might be safer to fail validation and force them to enter "12:00 noon", or even reject "12:00" completely and make them enter "12:01 PM", which is (I think) unambiguous.
currenTime = "5/18/2017 05:55 AM"
timetwo = "5/18/2017 12:00 AM"
currentTime.isBefore(timetwo) => fails
When you say "fails" you means returns false - and this is expected. 5:55am is not before midnight as midnight is the start of the day, not the end of the day.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With