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
selffromJson()
public
static fromJson(string|null $json) : self
Parameters
- $json : string|null
Return values
selfintervalsFor()
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
boolisEmpty()
public
isEmpty() : bool
Return values
boolisNonstop()
public
isNonstop(int $dow) : bool
Parameters
- $dow : int
Return values
boolisOpenAt()
public
isOpenAt(DateTimeInterface $dt) : bool
Parameters
- $dt : DateTimeInterface
Return values
boolisOpenNow()
public
isOpenNow() : bool
Return values
boolisValidJson()
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
booltoArray()
public
toArray() : array<int, array<int, array{0: string, 1: string}>>
Return values
array<int, array<int, array{0: string, 1: string}>>toJson()
public
toJson() : string
Return values
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|nulltoMinutes()
private
static toMinutes(string $hhmm) : int
Parameters
- $hhmm : string