CoolCMS API

OpeningHours
in package

FinalYes

Opening hours: a typed value object over a JSON string stored in `AdvertParameterRel.value`.

The column stays text because of fulltext; JSON is only a serialization convention (compact times/numbers are below ft_min_token_size, so they do not pollute fulltext).

JSON shape: { "1": [["08:00","12:00"],["13:00","17:00"]], "6": [["00:00","24:00"]] }

  • keys "1".."7" = Monday to Sunday (ISO-8601 day of week)
  • value = list of [from, to] intervals in "HH:MM" (24h), at most 2 per day
  • closed = the key is missing or an empty array
  • nonstop = the single interval ["00:00","24:00"]

Table of Contents

Constants

MAX_INTERVALS_PER_DAY  : mixed = 2

Properties

$days  : array<int, array<int, array{0: string, 1: string}>>

Methods

fromArray()  : self
fromJson()  : self
intervalsFor()  : array<int, array{0: string, 1: string}>
isClosed()  : bool
isEmpty()  : bool
isNonstop()  : bool
isOpenAt()  : bool
isOpenNow()  : bool
isValidJson()  : bool
Validation for a form rule; an empty value is fine (not filled in).
toArray()  : array<int, array<int, array{0: string, 1: string}>>
toJson()  : string
__construct()  : mixed
normalizeTime()  : string|null
Normalizes "8:0" / "08:00" to "08:00"; "24:00" is allowed as the end of the day.
toMinutes()  : int

Constants

MAX_INTERVALS_PER_DAY

public mixed MAX_INTERVALS_PER_DAY = 2

Properties

$days

private array<int, array<int, array{0: string, 1: string}>> $days

normalized, open days only

Methods

fromArray()

public static fromArray(array<int|string, mixed> $data) : self
Parameters
$data : array<int|string, mixed>
Return values
self

fromJson()

public static fromJson(string|null $json) : self
Parameters
$json : string|null
Return values
self

intervalsFor()

public intervalsFor(int $dow) : array<int, array{0: string, 1: string}>
Parameters
$dow : int
Return values
array<int, array{0: string, 1: string}> —

intervals of the given day (empty means closed)

isClosed()

public isClosed(int $dow) : bool
Parameters
$dow : int
Return values
bool

isNonstop()

public isNonstop(int $dow) : bool
Parameters
$dow : int
Return values
bool

isOpenAt()

public isOpenAt(DateTimeInterface $dt) : bool
Parameters
$dt : DateTimeInterface
Return values
bool

isOpenNow()

public isOpenNow() : bool
Return values
bool

isValidJson()

Validation for a form rule; an empty value is fine (not filled in).

public static isValidJson(string|null $json) : bool
Parameters
$json : string|null
Return values
bool

toArray()

public toArray() : array<int, array<int, array{0: string, 1: string}>>
Return values
array<int, array<int, array{0: string, 1: string}>>

__construct()

private __construct(array<int, array<int, array{0: string, 1: string}>> $days) : mixed
Parameters
$days : array<int, array<int, array{0: string, 1: string}>>

normalizeTime()

Normalizes "8:0" / "08:00" to "08:00"; "24:00" is allowed as the end of the day.

private static normalizeTime(string $value) : string|null
Parameters
$value : string
Return values
string|null

toMinutes()

private static toMinutes(string $hhmm) : int
Parameters
$hhmm : string
Return values
int
On this page

Search results