Skip to main content

AvailabilityRepository

\Benecaster\Availability\AvailabilityRepository

Class Free

Reads and writes episode/tier availability rows, and owns the conversion between the two time representations availability uses. Stored availability datetimes are UTC. The values callers pass in, and the values a podcaster types into the episode editor, are site-local — the repository converts on the way in, so every write passes through one point regardless of which caller made it. Anything that reads availability rows directly and renders a datetime to a human must convert it back with to_local(). That is the leg that fails quietly: a bad write releases an episode at the wrong time, which someone notices, while a bad read simply shows a podcaster a time that is not true. Availability is stored absolute rather than as a naive local time because a naive local time is undecidable twice a year — one wall-clock hour happens twice on the fall-back night and another does not exist at all on the spring-forward night. No amount of consistency in the comparison fixes that, because the ambiguity is in the stored value.

Methods

Method Visibility Since Description
to_utc( string $local_datetime ): string Public Converts a site-local Y-m-d H:i:s datetime to UTC. Resolves against the site's timezone (Settings → General) — the timezone the podcaster typed their wall-clock value in — not against PHP's process timezone, which WordPress does not guarantee matches it. Empty or whitespace-only input is returned unchanged rather than becoming an epoch date.
to_local( string $utc_datetime ): string Public Converts a stored UTC Y-m-d H:i:s datetime back to the site's timezone for display. Call this before showing any stored availability datetime to a human — a datetime-local input is timezone-naive, so a UTC value handed to one displays as the wrong hour with nothing on screen indicating it. Empty or whitespace-only input is returned unchanged.