PHP Luminova: Tasks Date & Time Validations Utility
Check whether an event has started, expired, or reached its reminder threshold.
Use Task for time-based decisions such as activating a promotion or sending a subscription reminder. Its methods compare a target date with the current time. For date arithmetic and formatting, see Immutable Date and Time Operations.
For an opening window, compare both boundaries explicitly:
use Luminova\Time\Time;
$now = Time::now('UTC');
$opening = $now->setTime(8, 0);
$closing = $now->setTime(17, 0);
$isOpen = $now >= $opening && $now < $closing;Class Definition
- Class namespace:
Luminova\Time\Task
Methods
expired
Check if a given date and time has passed.
public static function expired(string $datetime, DateTimeZone|string|null $timezone = 'UTC'): boolParameters:
| Parameter | Type | Description |
|---|---|---|
$datetime | string | The expiration date and time (e.g., '2023-09-25 08:00AM'). |
$timezone | DateTimeZone|string|null | Optional timezone string. |
Return:
bool - Returns true if the task has expired, false otherwise.
Useful for checking if a deal or promo code has expired.
before
Check whether the reminder threshold has been reached. Pair this with expired() when reminders should stop at expiration.
public static function before(string $datetime, int $days = 2, DateTimeZone|string|null $timezone = 'UTC'): boolParameters:
| Parameter | Type | Description |
|---|---|---|
$datetime | string | Expiration date and time in Y-m-d H:iA format. |
$days | int | Number of days to check before expiration (default: 2). |
$timezone | DateTimeZone|string|null | Pass a DateTimeZone instance for explicit timezone handling. |
Return:
bool - Returns true at or after the reminder threshold, including after expiration.
Throws:
- Luminova\Exceptions\InvalidArgumentException - If
$daysis less than 1.
Example:
use Luminova\Time\Task;
use Luminova\Time\Time;
$zone = new DateTimeZone('UTC');
$expiry = Time::now($zone)->modify('+1 day')->setTime(8, 0)->format('Y-m-d H:iA');
$shouldRemind = Task::before($expiry, 2, $zone)
&& !Task::expired($expiry, $zone);started
Check if a given datetime has started, or if it should be treated asstarted earlier using a "before" offset.
public static function started(
string $datetime,
int $before = 0,
DateTimeZone|string|null $timezone = 'UTC'
): boolParameters:
| Parameter | Type | Description |
|---|---|---|
$datetime | string | The target date and time (e.g. "2025-01-10 10:00"). |
$before | int | Seconds to move the start earlier. Zero and negative values leave the start unchanged (default 0). |
$timezone | DateTimeZone|string|null | Timezone to use for both values (default 'UTC'). |
Return:
bool - Returns true if the event has started, or the early-start threshold has passed.
Example:
use Luminova\Time\Task;
use Luminova\Time\Time;
$startsAt = Time::now('UTC')->modify('+30 minutes')->format('Y-m-d H:i:s');
$canPreview = Task::started($startsAt, before: 3600, timezone: 'UTC');