I have two Zend_Date that represent an interval :
$start = new Zend_Date($punch->getStart());
$end = new Zend_Date($punch->getEnd());
$nbHours = $start->sub($end , Zend_Date::HOUR);
$nbMinutes = $start->sub($end , Zend_Date::MINUTE);
$hoursTotal = $nbHours->get(Zend_Date::HOUR);
$minutesTotal = $nbMinutes->get(Zend_Date::MINUTE);
Is there an simple way to split the interval by day of the week with Zend_Date when the interval > 24 hours?
For example, if I have an interval from Monday 8am to Tuesday 4:30pm, I would like to have an array containing monday = 16h and tuesday = 16:30.
You don't need to use Zend_Date for this, in fact it is probably better not to. You should use the date/time classes in PHP instead.
If I understand your question correctly you want an array of days and the hours worked for those days.
I first created a mock class to reflect your code example, I have assumed it is returning timestamps:-
Then we set up the DateTime objects-
Then we use a DateInterval object to generate our iterable DatePeriod:-
Then we simply iterate over it counting the minutes worked in each day:-
See the manual page for acceptable formats.
We now have the number of minutes worked in each day, converting them to hours is trivial:-
Output (Obviously, you will get a different result running it at a different time) :-
So on Monday 17.48 hours were worked and 19.27 on Tuesday.
Alternatively:-
Would give the following output if that is closer to what you want:-
That's the simplest way I can think of doing it.