I have the php code below comparing two times against the current time using strtotime:
$timingsfirstTime[0] = date("H:i:s", strtotime(trim($showTimings[0])));
$timingslastTime[2] = date("H:i:s", strtotime(trim($showTimings[2])));
// Confirm that the start time of the frist show is greater than the last time of last show on the channel
$current_time = date("H:i:s",strtotime('now'));
$this->assertTrue(($current_time > $timingsfirstTime[0] && $current_time < $timingslastTime[2]),"current time ".$current_time. " is not greater than current show start time ". $timingsfirstTime[0] . " or current time is not less than current show end time ".$timingslastTime[2]);
But my the assertion fails somehow and outputs:
current time 00:38:45 is not greater than current show start time 23:50:00 or current time is not less than current show end time 00:50:00
You’re doing string comparisons, not date comparisons, which is why it’s “failing”.
Use
DateTimeinstead, since it’s easier to read, less code, and can be compared natively. I would also split your assertion into two assertions to make it easier to tell what case failed: