public function getNextDate($curdate) { $next_day_of_month = date('j', $curdate); if ($this->week_of_month && $this->day_of_week) { return $this->getNthDayOfWeek($curdate, $this->day_of_week, $this->week_of_month); } else { if (sizeof($this->days_of_month) > 0) { $next_day_of_month = $this->getNextDayOfMonth($next_day_of_month); while (TribeDateUtils::getLastDayOfMonth($curdate) < $next_day_of_month) { $next_day_of_month = $this->days_of_month[0]; $curdate = mktime(date("H", $curdate), date("i", $curdate), date("s", $curdate), date('n', $curdate) + $this->months_between, 1, date('Y', $curdate)); } } if ($next_day_of_month > date('j', $curdate)) { // no need to jump ahead stay in current month return mktime(date("H", $curdate), date("i", $curdate), date("s", $curdate), date('n', $curdate), $next_day_of_month, date('Y', $curdate)); } else { $nextdate = mktime(date("H", $curdate), date("i", $curdate), date("s", $curdate), date('n', $curdate) + $this->months_between, 1, date('Y', $curdate)); while (TribeDateUtils::getLastDayOfMonth($nextdate) < $next_day_of_month) { $nextdate = mktime(date("H", $curdate), date("i", $curdate), date("s", $curdate), date('n', $nextdate) + $this->months_between, 1, date('Y', $nextdate)); } return mktime(date("H", $curdate), date("i", $curdate), date("s", $curdate), date('n', $nextdate), $next_day_of_month, date('Y', $nextdate)); } } }
public function setup_list($template_file) { if (basename(dirname($template_file)) . '/' . basename($template_file) == 'mini-calendar/list.php') { if ($this->args['count'] == 0) { return; } // make sure the widget taxonomy filter setting is respected add_action('pre_get_posts', array($this, 'set_count'), 1000); global $wp_query; // hijack the main query to load the events via provided $args if (!is_null($this->args)) { $query_args = array('posts_per_page' => $this->args['count'], 'tax_query' => $this->args['tax_query'], 'eventDisplay' => 'custom', 'start_date' => $this->get_month(), 'post_status' => array('publish'), 'is_tribe_mini_calendar' => true, 'tribeHideRecurrence' => false); // set end date if initial load, or ajax month switch if (!defined('DOING_AJAX') || defined('DOING_AJAX') && $_POST['action'] == 'tribe-mini-cal') { $query_args['end_date'] = substr_replace($this->get_month(TribeDateUtils::DBDATEFORMAT), TribeDateUtils::getLastDayOfMonth(strtotime($this->get_month())), -2); // @todo use tribe_events_end_of_day() ? $query_args['end_date'] = TribeDateUtils::endOfDay($query_args['end_date']); } $wp_query = TribeEventsQuery::getEvents($query_args, true); } } }
/** * Gets the last day of the week in a month (ie the last Tuesday). Passing in -1 gives you the last day in the month. * * @param int $curdate A timestamp. * @param int $day_of_week The index of the day of the week. * * @return int The timestamp of the date that fits the qualifications. */ public static function getLastDayOfWeekInMonth($curdate, $day_of_week) { $nextdate = mktime(date("H", $curdate), date("i", $curdate), date("s", $curdate), date('n', $curdate), TribeDateUtils::getLastDayOfMonth($curdate), date('Y', $curdate)); while (date('N', $nextdate) != $day_of_week && $day_of_week != -1) { $nextdate = strtotime(date(DateSeriesRules::DATE_FORMAT, $nextdate) . " - 1 day"); } return $nextdate; }