Inventory_Presser_Shortcode_Hours_Today::find_next_open_day( array $days )

Takes an array of days and finds the next day the business has hours.

Description Description

Does not check if the business is still open today. Helps make the jump from Friday to the next open day on Monday.


Top ↑

Parameters Parameters

$days

(array) (Required) An array of Inventory_Presser_Business_Day objects


Top ↑

Return Return

(Inventory_Presser_Business_Day) The next day that has open hours


Top ↑

Source Source

File: includes/shortcode/class-shortcode-hours-today.php

	public static function find_next_open_day( $days ) {
		// find today
		$today_weekday = gmdate( 'w', current_time( 'timestamp' ) ); // 0 if today is Sunday
		$after_day     = null;
		$before_day    = null;
		$open_days     = array_filter(
			$days,
			function ( $day ) {
				return $day->open_in_some_fashion();
			}
		);
		foreach ( $open_days as $day ) {
			if ( $day->weekday > $today_weekday && ( null === $after_day || $day->weekday < $after_day->weekday ) ) {
				$after_day = $day;
			}
			if ( $day->weekday < $today_weekday && ( null === $before_day || $day->weekday < $before_day->weekday ) ) {
				$before_day = $day;
			}
		}
		return ( null === $after_day ? $before_day : $after_day );
	}