Jetpack_RelatedPosts::_get_coalesced_range PHP Method

_get_coalesced_range() protected method

Takes a range and coalesces it into a month interval bracketed by a time as determined by the blog_id to enhance caching.
protected _get_coalesced_range ( array $date_range ) : array
$date_range array
return array
    protected function _get_coalesced_range(array $date_range)
    {
        $now = time();
        $coalesce_time = $this->_blog_id_wpcom % 86400;
        $current_time = $now - strtotime('today', $now);
        if ($current_time < $coalesce_time && '01' == date('d', $now)) {
            // Move back 1 period
            return array('from' => date('Y-m-01', strtotime('-1 month', $date_range['from'])) . ' ' . date('H:i:s', $coalesce_time), 'to' => date('Y-m-01', $date_range['to']) . ' ' . date('H:i:s', $coalesce_time));
        } else {
            // Use current period
            return array('from' => date('Y-m-01', $date_range['from']) . ' ' . date('H:i:s', $coalesce_time), 'to' => date('Y-m-01', strtotime('+1 month', $date_range['to'])) . ' ' . date('H:i:s', $coalesce_time));
        }
    }