PHPackages                             effectra/clock - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. effectra/clock

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

effectra/clock
==============

The Effectra Clock package.

v2.0.0(3w ago)0261MITPHPPHP ^8.0.2

Since Jun 19Pushed 3w agoCompare

[ Source](https://github.com/effectra/clock)[ Packagist](https://packagist.org/packages/effectra/clock)[ RSS](/packages/effectra-clock/feed)WikiDiscussions main Synced 2w ago

READMEChangelog (2)Dependencies (9)Versions (3)Used By (1)

Effectra\\Clock
===============

[](#effectraclock)

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.

Features
--------

[](#features)

- Implements the `Psr\Clock\ClockInterface` interface
- Returns the current time as a `DateTimeImmutable` instance
- Returns the current Unix timestamp as an integer
- Formats current date and time in custom PHP date formats
- Supports date arithmetic with `add()` and `sub()`
- Calculates date differences with `diff()`
- Provides Gregorian/Hijri conversion helpers
- Exposes timezone and day-boundary utilities

Usage
-----

[](#usage)

```
use Effectra\Clock\Clock;

$clock = new Clock();

$currentDateTime = $clock->now();
$currentTimestamp = $clock->timestamp();
$formatted = $clock->format('Y-m-d H:i:s');
```

Public methods
--------------

[](#public-methods)

### `now(): \DateTimeImmutable`

[](#now-datetimeimmutable)

Returns the current date and time as a `DateTimeImmutable` object.

### `timestamp(): int`

[](#timestamp-int)

Returns the current Unix timestamp as an integer.

### `format(string $format = 'Y-m-d H:i:s'): string`

[](#formatstring-format--y-m-d-his-string)

Formats the current date and time using the provided PHP date format string.

### `date(string $format = 'Y-m-d'): string`

[](#datestring-format--y-m-d-string)

Returns the current date only, formatted with the supplied format.

### `time(string $format = 'H:i:s'): string`

[](#timestring-format--his-string)

Returns the current time only, formatted with the supplied format.

### `dayOfWeek(bool $short = false): string`

[](#dayofweekbool-short--false-string)

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`.

### `month(bool $short = false): string`

[](#monthbool-short--false-string)

Returns the current month name. If `$short` is `true`, it returns the abbreviated month name.

### `year(): int`

[](#year-int)

Returns the current year as an integer.

### `isLeapYear(): bool`

[](#isleapyear-bool)

Checks whether the current year is a leap year.

### `daysInMonth(): int`

[](#daysinmonth-int)

Returns the number of days in the current month.

### `toTimestamp(string $dateTime): int`

[](#totimestampstring-datetime-int)

Converts a date string into a Unix timestamp.

### `add(string $interval, int $value = 1): \DateTimeImmutable`

[](#addstring-interval-int-value--1-datetimeimmutable)

Adds a time interval to the current time. Example: `add('days', 2)`.

### `sub(string $interval, int $value = 1): \DateTimeImmutable`

[](#substring-interval-int-value--1-datetimeimmutable)

Subtracts a time interval from the current time.

### `diff(string $date1, string $date2, string $format = '%a days'): string`

[](#diffstring-date1-string-date2-string-format--a-days-string)

Calculates the difference between two dates and formats it using the supplied DateInterval format string.

### `toHijri(?int $year = null, ?int $month = null, ?int $day = null, bool $arabicNames = true): array`

[](#tohijriint-year--null-int-month--null-int-day--null-bool-arabicnames--true-array)

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.

### `hijriNow(bool $arabicNames = true): array`

[](#hijrinowbool-arabicnames--true-array)

Returns the current Hijri date information using the same structure as `toHijri()`.

### `hijriFormat(string $format = 'd F Y', bool $arabicNames = true): string`

[](#hijriformatstring-format--d-f-y-bool-arabicnames--true-string)

Formats the current Hijri date using a simplified token format such as `d`, `j`, `F`, `M`, `m`, `n`, `Y`, and `y`.

### `timezoneInfo(): array`

[](#timezoneinfo-array)

Returns information about the current timezone, including the timezone name, offset in seconds, offset in hours, and whether daylight saving time is active.

### `setTimezone(string $timezone): bool`

[](#settimezonestring-timezone-bool)

Sets the default timezone and returns whether the operation succeeded.

### `microtime(): float`

[](#microtime-float)

Returns the current timestamp with microseconds precision.

### `formatTimestamp(?int $timestamp = null, string $format = 'Y-m-d H:i:s'): string`

[](#formattimestampint-timestamp--null-string-format--y-m-d-his-string)

Formats a Unix timestamp into a readable string. If no timestamp is provided, the current timestamp is used.

### `isWeekend(?string $date = null): bool`

[](#isweekendstring-date--null-bool)

Checks whether the provided date is a weekend. If no date is given, it uses the current date.

### `dayBoundaries(?string $date = null): array`

[](#dayboundariesstring-date--null-array)

Returns the start and end of the day for a given date, along with their Unix timestamps.

Example
-------

[](#example)

```
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');
```

Contributing
------------

[](#contributing)

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.

License
-------

[](#license)

This package is open-source and available under the [MIT License](https://opensource.org/licenses/MIT). "# clock"

###  Health Score

42

—

FairBetter than 88% of packages

Maintenance95

Actively maintained with recent releases

Popularity6

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1133 days

Total

2

Last Release

23d ago

Major Versions

v1.0.0 → v2.0.02026-07-26

### Community

Maintainers

![](https://www.gravatar.com/avatar/7e6219ae87e98df8783b2f595b013035dd183c0712afd24045a8acf0a40c3bdf?d=identicon)[effectra](/maintainers/effectra)

---

Top Contributors

[![BMTmohammedtaha](https://avatars.githubusercontent.com/u/95439605?v=4)](https://github.com/BMTmohammedtaha "BMTmohammedtaha (6 commits)")

---

Tags

clockphppsr

###  Code Quality

TestsPest

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/effectra-clock/health.svg)

```
[![Health](https://phpackages.com/badges/effectra-clock/health.svg)](https://phpackages.com/packages/effectra-clock)
```

###  Alternatives

[symfony/symfony

The Symfony PHP framework

31.4k87.4M2.2k](/packages/symfony-symfony)[ecotone/ecotone

Enterprise architecture layer for Laravel and Symfony — CQRS, Event Sourcing, Durable Workflows (Sagas, Orchestrators), Projections, and Outbox messaging via PHP attributes.

568591.1k63](/packages/ecotone-ecotone)[symfony/clock

Decouples applications from the system clock

432219.5M509](/packages/symfony-clock)[mcp/sdk

Model Context Protocol SDK for Client and Server applications in PHP

1.6k2.2M145](/packages/mcp-sdk)[flow-php/etl

PHP ETL - Extract Transform Load - Abstraction

378637.6k126](/packages/flow-php-etl)[lcobucci/clock

Yet another clock abstraction

799213.0M189](/packages/lcobucci-clock)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
