Opening_Hours
Represents the opening hours of a restaurant in the order system.
Tags
Table of Contents
- $days_of_week : mixed
- $opening_times : array<string|int, mixed>
- $timezone : DateTimeZone
- __construct() : mixed
- Constructs a new Opening_Hours object based on the supplied opening times.
- get_current_day_of_week() : string
- Get the current day of the week. Returned in English lowercase. Used in arrays as the day 'key'.
- get_days_of_week() : mixed
- Get the days of the week array used internally to create and process opening times. These days are not localized - see @return array The days of the week
- get_opening_times() : array<string|int, mixed>
- Get all opening times as an array, or if $day is passed the opening times for the specified day.
- has_additional_opening_periods() : bool
- Checks if there is more than one opening period specified on any day of the week.
- is_open() : bool
- Is the restaurant currently open?
- is_valid() : bool
- Are the opening hours valid? It is considered valid if there's at least one opening period defined for at least one day.
- next_closing_time() : DateTimeInterface|false
- Get the next closing time if the restaurant is currently open.
- next_opening_time() : DateTimeInterface|false
- Get the next opening time for the restaurant. If the restaurant is currently open, the next opening time (not the opening time of the current period) is returned. The datetime returned will have the correct day of the week set.
- get_day_of_week() : string
- Get the day of the week for the given datetime. Returns the 'l' format in English lowercase, e.g. 'monday'
- get_first_opening_periods() : mixed
- get_opening_periods() : array<string|int, mixed>
- Get all opening periods for the specified period number (1 or 2).
- get_second_opening_periods() : mixed
- is_valid_opening_period() : mixed
- opening_periods_to_datetimes() : mixed
- parse_times() : mixed
Properties
$days_of_week
private
static mixed
$days_of_week
= null
Tags
$opening_times
private
array<string|int, mixed>
$opening_times
Holds the complete opening times array [ day of week => [ array of open periods ] ]
Tags
$timezone
private
DateTimeZone
$timezone
The current timezone, retrieved from WordPress.
Tags
Methods
__construct()
Constructs a new Opening_Hours object based on the supplied opening times.
public
__construct([array<string|int, mixed> $opening_times = [] ]) : mixed
Parameters
- $opening_times : array<string|int, mixed> = []
-
The opening times array.
Tags
Return values
mixed —get_current_day_of_week()
Get the current day of the week. Returned in English lowercase. Used in arrays as the day 'key'.
public
static get_current_day_of_week() : string
Tags
Return values
string —The day of the week, e.g. 'monday'
get_days_of_week()
Get the days of the week array used internally to create and process opening times. These days are not localized - see @return array The days of the week
public
static get_days_of_week() : mixed
Tags
Return values
mixed —get_opening_times()
Get all opening times as an array, or if $day is passed the opening times for the specified day.
public
get_opening_times([string $day = null ]) : array<string|int, mixed>
Parameters
- $day : string = null
-
The day of the week to retrieve times for (optional). E.g. 'monday'.
Tags
Return values
array<string|int, mixed> —The opening times array.
has_additional_opening_periods()
Checks if there is more than one opening period specified on any day of the week.
public
has_additional_opening_periods() : bool
Tags
Return values
bool —true if there are multiple opening periods on any day, false otherwise.
is_open()
Is the restaurant currently open?
public
is_open([string $time = 'now' ]) : bool
Parameters
- $time : string = 'now'
-
The time to check against. Defaults to 'now'
Tags
Return values
bool —true if the restaurant is currently open, false if closed.
is_valid()
Are the opening hours valid? It is considered valid if there's at least one opening period defined for at least one day.
public
is_valid() : bool
Tags
Return values
bool —true if at least one day has one opening period, false otherwise.
next_closing_time()
Get the next closing time if the restaurant is currently open.
public
next_closing_time() : DateTimeInterface|false
Tags
Return values
DateTimeInterface|false —The closing time (DateTime object), or false if there are no open periods or the restaurant is currently closed.
next_opening_time()
Get the next opening time for the restaurant. If the restaurant is currently open, the next opening time (not the opening time of the current period) is returned. The datetime returned will have the correct day of the week set.
public
next_opening_time() : DateTimeInterface|false
Tags
Return values
DateTimeInterface|false —The datetime of the next opening time, or false if there are no valid open periods.
get_day_of_week()
Get the day of the week for the given datetime. Returns the 'l' format in English lowercase, e.g. 'monday'
private
static get_day_of_week(DateTimeInterface $datetime) : string
Parameters
- $datetime : DateTimeInterface
-
The datetime to get the day for
Tags
Return values
string —The day of the week, e.g. 'monday'
get_first_opening_periods()
private
get_first_opening_periods() : mixed
Tags
Return values
mixed —get_opening_periods()
Get all opening periods for the specified period number (1 or 2).
private
get_opening_periods(int $period_number) : array<string|int, mixed>
Parameters
- $period_number : int
-
The period number - 1 or 2
Tags
Return values
array<string|int, mixed> —The opening periods, or an empty array if there are none.
get_second_opening_periods()
private
get_second_opening_periods() : mixed
Tags
Return values
mixed —is_valid_opening_period()
private
is_valid_opening_period(mixed $period) : mixed
Parameters
- $period : mixed
Tags
Return values
mixed —opening_periods_to_datetimes()
private
opening_periods_to_datetimes(mixed $day, array<string|int, mixed> $opening_periods) : mixed
Parameters
- $day : mixed
- $opening_periods : array<string|int, mixed>
Tags
Return values
mixed —parse_times()
private
parse_times(array<string|int, mixed> $opening_times) : mixed
Parameters
- $opening_times : array<string|int, mixed>