/** * Return the date of the first day in the month view grid. * * This is not necessarily the last day of the specified month, rather it is the date of * the final grid cell which could be anything upto 6 days into the next month. * * @param string $month * @param int $start_of_week * * @return bool|string (Y-m-d) */ protected function calculate_final_cell_date($month, $start_of_week = null) { if (null === $start_of_week) { $start_of_week = (int) get_option('start_of_week', 0); } $last_day = TribeDateUtils::last_day_in_month($month); $end_of_week = TribeDateUtils::week_ends_on($start_of_week); if ($end_of_week < $last_day) { $end_of_week += 7; } $diff = $end_of_week - $last_day; if ($diff >= 0) { $diff = "+{$diff}"; } try { $date = new DateTime($month); $date = new DateTime($date->format('Y-m-t')); $date->modify("{$diff} days"); return $date->format(TribeDateUtils::DBDATEFORMAT); } catch (Exception $e) { return false; } }