PHPackages                             solodkiy/date-time - 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. solodkiy/date-time

Abandoned → [solodkiy/brick-date-time](/?search=solodkiy%2Fbrick-date-time)Library[Utility &amp; Helpers](/categories/utility)

solodkiy/date-time
==================

Date and time library

104.0.0(4mo ago)12.1kMITPHPPHP ^8.1CI passing

Since Oct 4Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/solodkiy/brick-date-time)[ Packagist](https://packagist.org/packages/solodkiy/date-time)[ GitHub Sponsors](https://github.com/BenMorel)[ RSS](/packages/solodkiy-date-time/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (4)Versions (69)Used By (0)

Brick\\DateTime (solodkiy fork)
===============================

[](#brickdatetime-solodkiy-fork)

[![](https://raw.githubusercontent.com/brick/brick/master/logo.png)](https://raw.githubusercontent.com/brick/brick/master/logo.png)

A powerful set of immutable classes to work with dates and times.

[![Build Status](https://github.com/solodkiy/brick-date-time/workflows/Tests/badge.svg)](https://github.com/solodkiy/brick-date-time/actions)[![Coverage Status](https://camo.githubusercontent.com/30646aa094bc41df9015358735ae67a44200a2b7f9958488f097b5e039ac4fdf/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f736f6c6f646b69792f627269636b2d646174652d74696d652f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/solodkiy/brick-date-time?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/fcc6f6522bdf0a27cbb6fcc7c77ee0ea30b226a8eda4f7b205368df9532136b4/68747470733a2f2f706f7365722e707567782e6f72672f736f6c6f646b69792f627269636b2d646174652d74696d652f762f737461626c65)](https://packagist.org/packages/solodkiy/brick-date-time)[![Total Downloads](https://camo.githubusercontent.com/aeaf8fdd754f17a307c80132e0a757296f8be0b9bdf3db48ad24342ce5f352d9/68747470733a2f2f706f7365722e707567782e6f72672f736f6c6f646b69792f627269636b2d646174652d74696d652f646f776e6c6f616473)](https://packagist.org/packages/solodkiy/brick-date-time)[![License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](http://opensource.org/licenses/MIT)

Introduction
------------

[](#introduction)

This library builds an extensive API on top of the native PHP date-time classes, and adds missing concepts such as `LocalDate`, `LocalTime`, `YearMonth`, `MonthDay`, etc.

The classes follow the [ISO 8601](http://en.wikipedia.org/wiki/ISO_8601) standard for representing date and time concepts.

This component follows an important part of the JSR 310 (Date and Time API) specification from Java. Don't expect an exact match of class and method names though, as a number of differences exist for technical or practical reasons.

All the classes are immutable, they can be safely passed around without being affected.

Installation
------------

[](#installation)

This library is installable via [Composer](https://getcomposer.org/):

```
composer require solodkiy/brick-date-time
```

Requirements
------------

[](#requirements)

This library requires PHP 8.1 or later.

About this fork
---------------

[](#about-this-fork)

While this library is still under development, it is well tested and should be stable enough to use in production environments.

### New functional

[](#new-functional)

- new `UtcDateTime` class
- `Instant::toUtcDateTime()` method
- `LocalDateTime::fromSqlFormat()` method
- `LocalDateTime::toSqlFormat()` method
- `ZonedDateTime::fromSqlFormat()` method
- `ZonedDateTime::toSqlFormat()` method
- `ZonedDateTime::toUtcDateTime()` method
- `ZonedDateTime::toNativeFormat()` method
- `ZonedDateTime::toUtcSqlFormat()` method

### Compatibility with brick/date-time

[](#compatibility-with-brickdate-time)

solodkiy/brick-date-timebrick/date-time104.\*.\*0.7.\*103.\*.\*0.6.\*102.\*.\*0.5.\*101.\*.\*0.4.\*100.\*.\*0.3.2Overview
--------

[](#overview)

### Main classes

[](#main-classes)

The following classes/enums represent the date-time concepts:

- `DayOfWeek`: a day-of-week such as Monday (`enum`)
- `Duration`: a duration measured in seconds and nanoseconds
- `Instant`: a point in time, with a nanosecond precision
- `Interval`: a period of time between two instants
- `LocalDate`: an isolated date such as `2014-08-31`
- `LocalDateRange`: an inclusive range of local dates, such as `2014-01-01/2014-12-31`
- `LocalDateTime`: a date-time without a time-zone, such as `2014-08-31T10:15:30`
- `LocalTime`: an isolated time such as `10:15:30`
- `Month`: a month-of-year such as January (`enum`)
- `MonthDay`: a combination of a month and a day, without a year, such as `--12-31`
- `Period`: a date-based amount of time, such as '2 years, 3 months and 4 days'
- `TimeZoneOffset`: an offset-based time-zone, such as `+01:00`
- `TimeZoneRegion`: a region-based time-zone, such as `Europe/London`
- `Year`: a year in the [proleptic calendar](http://en.wikipedia.org/wiki/Proleptic_Gregorian_calendar)
- `YearMonth`: a combination of a year and a month, such as `2014-08`
- `ZonedDateTime`: a date-time with a time-zone, such as `2014-08-31T10:15:30+01:00`. This class is conceptually equivalent to the native `DateTime` class
- `UtcDateTime`: a date-time with a UTC time-zone, such as `2014-08-31T10:15:30Z`. This class is sub-class of ZonedDateTime

These classes belong to the `Brick\DateTime` namespace.

### Clocks

[](#clocks)

All objects read the current time from a `Clock` implementation. The following implementations are available:

- `SystemClock` returns the system time; it's the default clock
- `FixedClock`: returns a pre-configured time
- `OffsetClock`: adds an offset to another clock
- `ScaleClock`: makes another clock fast-forward by a scale factor

These classes belong to the `Brick\DateTime\Clock` namespace.

In your application, you will most likely never touch the defaults, and always use the default clock:

```
use Brick\DateTime\LocalDate;
use Brick\DateTime\TimeZone;

echo LocalDate::now(TimeZone::utc()); // 2017-10-04
```

In your tests however, you might need to set the current time to test your application in known conditions. To do this, you can either explicitly pass a `Clock` instance to `now()` methods:

```
use Brick\DateTime\Clock\FixedClock;
use Brick\DateTime\Instant;
use Brick\DateTime\LocalDate;
use Brick\DateTime\TimeZone;

$clock = new FixedClock(Instant::of(1000000000));
echo LocalDate::now(TimeZone::utc(), $clock); // 2001-09-09
```

Or you can change the *default* clock for all date-time classes. All methods such as `now()`, unless provided with an explicit Clock, will use the default clock you provide:

```
use Brick\DateTime\Clock\FixedClock;
use Brick\DateTime\DefaultClock;
use Brick\DateTime\Instant;
use Brick\DateTime\LocalDate;
use Brick\DateTime\TimeZone;

DefaultClock::set(new FixedClock(Instant::of(1000000000)));
echo LocalDate::now(TimeZone::utc()); // 2001-09-09

DefaultClock::reset(); // do not forget to reset the clock to the system clock!
```

There are also useful shortcut methods to use clocks in your tests, inspired by [timecop](https://github.com/travisjeffery/timecop):

- `freeze()` freezes time to a specific point in time
- `travelTo()` travels to an `Instant` in time, but allows time to continue moving forward from there
- `travelBy()` travels in time by a `Duration`, which may be forward (positive) or backward (negative)
- `scale()` makes time move at a given pace

#### Freeze the time to a specific point

[](#freeze-the-time-to-a-specific-point)

```
use Brick\DateTime\DefaultClock;
use Brick\DateTime\Instant;

DefaultClock::freeze(Instant::of(2000000000));

$a = Instant::now(); sleep(1);
$b = Instant::now();

echo $a, PHP_EOL; // 2033-05-18T03:33:20Z
echo $b, PHP_EOL; // 2033-05-18T03:33:20Z

DefaultClock::reset();
```

#### Travel to a specific point in time

[](#travel-to-a-specific-point-in-time)

```
use Brick\DateTime\DefaultClock;
use Brick\DateTime\Instant;

DefaultClock::travelTo(Instant::of(2000000000));
$a = Instant::now(); sleep(1);
$b = Instant::now();

echo $a, PHP_EOL; // 2033-05-18T03:33:20.000342Z
echo $b, PHP_EOL; // 2033-05-18T03:33:21.000606Z

DefaultClock::reset();
```

#### Make time move at a given pace

[](#make-time-move-at-a-given-pace)

```
use Brick\DateTime\DefaultClock;
use Brick\DateTime\Instant;

DefaultClock::travelTo(Instant::of(2000000000));
DefaultClock::scale(60); // 1 second becomes 60 seconds

$a = Instant::now(); sleep(1);
$b = Instant::now();

echo $a, PHP_EOL; // 2033-05-18T03:33:20.00188Z
echo $b, PHP_EOL; // 2033-05-18T03:34:20.06632Z

DefaultClock::reset();
```

As you can see, you can even combine `travelTo()` and `scale()` methods.

Be very careful to **`reset()` the DefaultClock after each of your tests!** If you're using PHPUnit, a good place to do this is in the `tearDown()` method.

### Exceptions

[](#exceptions)

The following exceptions can be thrown:

- `Brick\DateTime\DateTimeException` when an illegal operation is performed
- `Brick\DateTime\Parser\DateTimeParseException` when `parse()`ing an invalid string representation

### Doctrine mappings

[](#doctrine-mappings)

You can use `brick/date-time` types in your Doctrine entities using the [brick/date-time-doctrine](https://github.com/brick/date-time-doctrine) package.

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

[](#contributing)

Before submitting a pull request, you can check the code using the following tools. Your CI build will fail if any of the following tools reports any issue.

First of all, install dependencies:

```
composer install
```

### Unit tests

[](#unit-tests)

Run PHPUnit tests:

```
vendor/bin/phpunit
```

### Static analysis

[](#static-analysis)

Run Psalm static analysis:

```
vendor/bin/psalm --no-cache
```

### Coding Style

[](#coding-style)

Install Easy Coding Standard in its own folder:

```
composer install --working-dir=tools/ecs
```

Run coding style analysis checks:

```
tools/ecs/vendor/bin/ecs check --config tools/ecs/ecs.php
```

Or fix issues found directly:

```
tools/ecs/vendor/bin/ecs check --config tools/ecs/ecs.php --fix
```

### Rector automated refactoring

[](#rector-automated-refactoring)

Install Rector in its own folder:

```
composer install --working-dir=tools/rector
```

Run automated refactoring:

```
tools/rector/vendor/bin/rector --config tools/rector/rector.php
```

###  Health Score

53

—

FairBetter than 97% of packages

Maintenance77

Regular maintenance activity

Popularity17

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity86

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 77% 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 ~49 days

Recently: every ~160 days

Total

62

Last Release

125d ago

Major Versions

0.4.1 → 100.0.02022-08-27

0.5.1 → 102.0.02023-08-14

0.6.0 → v102.x-dev2024-01-10

0.6.4 → 103.0.02024-05-03

103.1.0 → 104.0.02026-01-05

PHP version history (5 changes)0.1.0PHP &gt;=7.1

0.2.1PHP ^7.1|^8.0

0.2.3PHP ^7.1 || ^8.0

0.4.0PHP ^7.4 || ^8.0

0.6.0PHP ^8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1427813?v=4)[Alexey Solodkiy](/maintainers/solodkiy)[@solodkiy](https://github.com/solodkiy)

---

Top Contributors

[![BenMorel](https://avatars.githubusercontent.com/u/1952838?v=4)](https://github.com/BenMorel "BenMorel (359 commits)")[![solodkiy](https://avatars.githubusercontent.com/u/1427813?v=4)](https://github.com/solodkiy "solodkiy (54 commits)")[![gnutix](https://avatars.githubusercontent.com/u/310134?v=4)](https://github.com/gnutix "gnutix (24 commits)")[![jiripudil](https://avatars.githubusercontent.com/u/1042159?v=4)](https://github.com/jiripudil "jiripudil (5 commits)")[![someniatko](https://avatars.githubusercontent.com/u/15856706?v=4)](https://github.com/someniatko "someniatko (3 commits)")[![szepeviktor](https://avatars.githubusercontent.com/u/952007?v=4)](https://github.com/szepeviktor "szepeviktor (3 commits)")[![antonkomarev](https://avatars.githubusercontent.com/u/1849174?v=4)](https://github.com/antonkomarev "antonkomarev (3 commits)")[![tigitz](https://avatars.githubusercontent.com/u/1524501?v=4)](https://github.com/tigitz "tigitz (2 commits)")[![ihmels](https://avatars.githubusercontent.com/u/9105856?v=4)](https://github.com/ihmels "ihmels (2 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (2 commits)")[![JodyLognoul](https://avatars.githubusercontent.com/u/943653?v=4)](https://github.com/JodyLognoul "JodyLognoul (1 commits)")[![kagmole](https://avatars.githubusercontent.com/u/4670130?v=4)](https://github.com/kagmole "kagmole (1 commits)")[![morrislaptop](https://avatars.githubusercontent.com/u/67807?v=4)](https://github.com/morrislaptop "morrislaptop (1 commits)")[![adrolter](https://avatars.githubusercontent.com/u/399091?v=4)](https://github.com/adrolter "adrolter (1 commits)")[![rodnaph](https://avatars.githubusercontent.com/u/447579?v=4)](https://github.com/rodnaph "rodnaph (1 commits)")[![francislavoie](https://avatars.githubusercontent.com/u/2111701?v=4)](https://github.com/francislavoie "francislavoie (1 commits)")[![bdsl](https://avatars.githubusercontent.com/u/159481?v=4)](https://github.com/bdsl "bdsl (1 commits)")[![andreaswolf](https://avatars.githubusercontent.com/u/159919?v=4)](https://github.com/andreaswolf "andreaswolf (1 commits)")[![GrahamCampbell](https://avatars.githubusercontent.com/u/2829600?v=4)](https://github.com/GrahamCampbell "GrahamCampbell (1 commits)")

---

Tags

instantbrickdatetimetimedateintervaldurationperiodstopwatchtimezonelocaldateMonthYearDayOfWeekLocalDateRangeLocalDateTimeLocalTimeMonthDayYearMonthYearMonthRangeYearWeekZonedDateTime

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/solodkiy-date-time/health.svg)

```
[![Health](https://phpackages.com/badges/solodkiy-date-time/health.svg)](https://phpackages.com/packages/solodkiy-date-time)
```

###  Alternatives

[brick/date-time

Date and time library

3623.3M60](/packages/brick-date-time)[league/period

Time range API for PHP

7335.4M21](/packages/league-period)[knplabs/knp-time-bundle

Making your dates and durations look sensible and descriptive

6308.9M39](/packages/knplabs-knp-time-bundle)[aeon-php/calendar

PHP type safe, immutable calendar library

2079.7M16](/packages/aeon-php-calendar)[dater/dater

Compact PHP library for working with date/time in different formats &amp; timezones.

14282.3k](/packages/dater-dater)[fresh/datetime

PHP library that provides additional functions for processing dates &amp; times.

17513.8k2](/packages/fresh-datetime)

PHPackages © 2026

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