Luminova Framework

Tasks

Last updated: 2024-04-22 23:50:32

The Task class is a utility class shipped with Luminova framework, designed to provide convenient methods for working with date and time-related operations in your application. By encapsulating common date and time functionality into static methods, to simplify the process of performing tasks like expiration checking, and interval calculations.


Features

Status Checking

With the isOpen and expired methods, developers can easily determine whether a task is currently open or has already expired, based on specified opening and closing times or expiration dates in a specific timezone.

Pre-Expiration Checks

The before method allows developer to perform pre-expiration checks, useful for sending notifications or taking actions before a task's expiration date.

Time Interval Calculation

Developers can leverage the passed method to determine if a certain amount of time has elapsed since a given timestamp, enhancing time-based logic and decision-making in applications.


  • Class namespace: \Luminova\Time\Task

Methods

isOpen

Check if the current time is between opening and closing times.

public static isOpen(string $openDatetime, string $closeDatetime, null|\DateTimeZone|string $timezone = 'UTC'): bool

Parameters:

ParameterTypeDescription
$openDatetimestringOpening date and time (e.g., '2023-09-25 08:00AM').
$closeDatetimestringClosing date and time (e.g., '2023-09-25 05:00PM').
$timezonenull|\DateTimeZone|stringOptional timezone string.

Return Value:

bool - Returns true if the task is still open, false otherwise.

This utility function is useful for checking business opening and closing hours.


expired

Check if a given date and time has passed.

public static expired(string $datetime, null|\DateTimeZone|string $timezone = 'UTC'): bool

Parameters:

ParameterTypeDescription
$datetimestringThe expiration date and time (e.g., '2023-09-25 08:00AM').
$timezonenull|\DateTimeZone|stringOptional timezone string.

Return Value:

bool - Returns true if the task has expired, false otherwise.

Useful for checking if a deal or promo code has expired.


before

Check if the given date is within a specified number of days before expiration.

public static before(string $datetime, int $days = 2, null|\DateTimeZone|string $timezone = 'UTC'): bool

Parameters:

ParameterTypeDescription
$datetimestringExpiration date and time (e.g., '2023-09-25 08:00AM').
$daysintNumber of days to check before expiration (default: 2).
$timezonenull|\DateTimeZone|stringOptional timezone string.

Return Value:

bool - Returns true if it's within the specified number of days before expiration.

Throws:

This method is useful to check and send notification days before subscription expiration.