Opening_Hours_Formatter

Tags

Table of Contents

DAYS_INDEX  = ['sunday' => 0, 'monday' => 1, 'tuesday' => 2, 'wednesday' => 3, 'thursday' => 4, 'friday' => 5, 'saturday' => 6]
format()  : array<string|int, mixed>
Format the opening times object, localized to the current locale. Days of the week are returned in the current language. Times are formatted based on the WP default time format.
format_open_close_time()  : string
Formats an open or close time for a restaurant. Times are formatted based on the WP default time format.
format_periods_for_day()  : array<string|int, mixed>
Format the opening times for a given day, localized to the current locale. Times are formatted based on the WP default time format.
get_time_format()  : mixed

Constants

DAYS_INDEX

private mixed DAYS_INDEX = ['sunday' => 0, 'monday' => 1, 'tuesday' => 2, 'wednesday' => 3, 'thursday' => 4, 'friday' => 5, 'saturday' => 6]
Tags

Methods

format()

Format the opening times object, localized to the current locale. Days of the week are returned in the current language. Times are formatted based on the WP default time format.

public static format(Opening_Hours $hours) : array<string|int, mixed>

Return format: array [ 'monday' => [ 'label' => 'Monday', 'periods' => [ 1 => [ 'from' => '10:00am', 'to => '2:00pm' ], 2 => [ 'from' => '10:00am', 'to' => '2:00pm' ] ] ], 'tuesday' => etc... ]

Parameters
$hours : Opening_Hours

The opening hours to format

Tags
Return values
array<string|int, mixed>

A localized array of opening times

format_open_close_time()

Formats an open or close time for a restaurant. Times are formatted based on the WP default time format.

public static format_open_close_time(DateTimeInterface $datetime[, bool $include_day = false ]) : string
Parameters
$datetime : DateTimeInterface

The datetime object to format

$include_day : bool = false

Whether to include the day in the formatted time, if the open/close time is a different day to today.

Tags
Return values
string

The formatted time

format_periods_for_day()

Format the opening times for a given day, localized to the current locale. Times are formatted based on the WP default time format.

public static format_periods_for_day(string $day, array<string|int, mixed> $opening_periods) : array<string|int, mixed>

Return format: array [ 'label' => 'Monday', 'periods' => [ 1 => [ 'from' => '10:00am', 'to => '2:00pm' ], 2 => [ 'from' => '10:00am', 'to' => '2:00pm' ] ] ]

Parameters
$day : string

The day of the week - 'monday' through 'sunday' in English lowercase

$opening_periods : array<string|int, mixed>

The opening periods for the day to format

Tags
Return values
array<string|int, mixed>

A localized array of opening times

Search results