Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Ok, this seems to be working correctly:</p> <pre><code> /** * Calculate time blocks from range * * @return array Returns array of blocks */ public function calculate() { $result = array(); $rangeStart = $this-&gt;rangeStart; $blockStart = $this-&gt;blockStart; $blockDuration = $this-&gt;blockDuration; do { // Reset end range $rangeEnd = clone $this-&gt;rangeEnd; // Set block's starting date to range's start date $blockStart-&gt;setDate($rangeStart-&gt;format('Y'), $rangeStart-&gt;format('m'), $rangeStart-&gt;format('d')); $blockEnd = clone $blockStart; $blockEnd-&gt;modify("+$blockDuration seconds"); // It's not last day of range, so it's full day if ($rangeStart-&gt;format("Ymd") !== $this-&gt;rangeEnd-&gt;format("Ymd")) { $rangeEnd-&gt;setDate($blockEnd-&gt;format('Y'), $blockEnd-&gt;format('m'), $blockEnd-&gt;format('d')); $rangeEnd-&gt;setTime($blockEnd-&gt;format('G'), $blockEnd-&gt;format('i'), $blockEnd-&gt;format('s')); if ($rangeEnd &gt; $this-&gt;rangeEnd) { $rangeEnd-&gt;setTime(0, 0, 0); } } // It's first day of range, so it's probably partial day if ($rangeStart-&gt;format("Ymd") === $this-&gt;rangeStart-&gt;format("Ymd")) { if ($rangeStart &lt; $blockStart) { $rangeStart-&gt;setTime($blockStart-&gt;format('G'), $blockStart-&gt;format('i'), $blockStart-&gt;format('s')); } } // Add to results if ($rangeStart &lt; $rangeEnd) { $result[] = array(clone $rangeStart, clone $rangeEnd); } // Full day after first iteration $rangeStart-&gt;setTime(0, 0, 0); $rangeStart-&gt;modify("+1 day"); } while ($blockEnd &lt;= $this-&gt;rangeEnd); return $result; } </code></pre> <p><strong>Edit</strong>: No, this one</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload