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