Effectra\Clock is a lightweight PHP utility class that implements Psr\Clock\ClockInterface. It provides common date and time helpers for applications, including formatting, date arithmetic, calendar checks, timezone management, and basic Hijri calendar support.
- Implements the
Psr\Clock\ClockInterfaceinterface - Returns the current time as a
DateTimeImmutableinstance - Returns the current Unix timestamp as an integer
- Formats current date and time in custom PHP date formats
- Supports date arithmetic with
add()andsub() - Calculates date differences with
diff() - Provides Gregorian/Hijri conversion helpers
- Exposes timezone and day-boundary utilities
use Effectra\Clock\Clock;
$clock = new Clock();
$currentDateTime = $clock->now();
$currentTimestamp = $clock->timestamp();
$formatted = $clock->format('Y-m-d H:i:s');Returns the current date and time as a DateTimeImmutable object.
Returns the current Unix timestamp as an integer.
Formats the current date and time using the provided PHP date format string.
Returns the current date only, formatted with the supplied format.
Returns the current time only, formatted with the supplied format.
Returns the current day of the week. If $short is true, it returns the short form such as Mon; otherwise it returns the full name such as Monday.
Returns the current month name. If $short is true, it returns the abbreviated month name.
Returns the current year as an integer.
Checks whether the current year is a leap year.
Returns the number of days in the current month.
Converts a date string into a Unix timestamp.
Adds a time interval to the current time. Example: add('days', 2).
Subtracts a time interval from the current time.
Calculates the difference between two dates and formats it using the supplied DateInterval format string.
Converts a Gregorian date to Hijri date data. If no year, month, or day is provided, it uses the current date. The result includes the Hijri year, month, day, month name, day of year, leap-year flag, and formatted strings.
Returns the current Hijri date information using the same structure as toHijri().
Formats the current Hijri date using a simplified token format such as d, j, F, M, m, n, Y, and y.
Returns information about the current timezone, including the timezone name, offset in seconds, offset in hours, and whether daylight saving time is active.
Sets the default timezone and returns whether the operation succeeded.
Returns the current timestamp with microseconds precision.
Formats a Unix timestamp into a readable string. If no timestamp is provided, the current timestamp is used.
Checks whether the provided date is a weekend. If no date is given, it uses the current date.
Returns the start and end of the day for a given date, along with their Unix timestamps.
use Effectra\Clock\Clock;
$clock = new Clock();
echo $clock->now()->format('Y-m-d H:i:s');
echo $clock->timestamp();
echo $clock->hijriFormat('d F Y');Contributions are welcome. If you find a bug or want to suggest an improvement, feel free to open an issue or submit a pull request.
This package is open-source and available under the MIT License. "# clock"