Adding hours
lsv opened this issue · 2 comments
lsv commented
I just began to add hours to days, so we can have a nice 1 day view
https://github.com/lsv/CalendR/tree/hours
But I just got stucked because of the iteration on the month get really weird.
$start = new \DateTime('2013-01-01');
$month = new Month($start);
$i = 0;
foreach ($month as $week) {
$this->assertInstanceOf('CalendR\\Period\\Week', $week);
foreach ($week as $day) {
/** @var Day $day */
$this->assertSame($start->format('d-m-Y'), $day->getBegin()->format('d-m-Y'));
$start->add(new \DateInterval('P1D'));
$i++;
}
}
$this->assertEquals($i, 31);
This actually gives me 35 in the last assert, and all assertSame is 1 day behind all the time.
yohang commented
Hi,
Iteration on month gives you weeks. Weeks contains days that can be out of the month.
In your case, you get, as extra days, 12/31/2012 (first day of the first week of 2013, which explain your 1 day offset), and 02/0(1,2,3)/2013, which are the 3 last days ogf the last week of january 2013.
If you want to iterate over the month days, you can use Month::getDays()
Yohan.
lsv commented
Oh yea, of course