I have been trying to use the DateTime class to calculate an interval.
I use the unix timestamp from $_SERVER['REQUEST_TIME'] and a time retrieved from the database to get an interval, which is of time DateInterval. That part works.
That interval could be, for example, 5 minutes and 10 seconds since a process began.
My expected time for that process to complete is 10 minutes, and I want to inform the user that there is 4 minutes, 50 seconds expected time left.
$running_time; // calculated before, type DateInterval. Echoing the formatted value shows correct time
// (only problem is no leading 0's for single-digit minutes/seconds in format: '%i:%s')
$total = new DateTime('10:00'); // ten minutes, 0 seconds expected total running time
$time_left = $total->diff(new DateTime($running_time->format('%i:%s'))); // fatal error
I think this would work, except that, oddly, the format function is not working as expected. The minutes and seconds do not have leading zeros when they are single digits.
Any hints?