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

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

nxmcz/date-time
===============

An DateTime class to deal with timestamp/DateTimeInterface

v1.4.5(1y ago)32721MITPHPPHP &gt;=8.4CI failing

Since Aug 7Pushed 1y ago1 watchersCompare

[ Source](https://github.com/nxmcz/date-time)[ Packagist](https://packagist.org/packages/nxmcz/date-time)[ RSS](/packages/nxmcz-date-time/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (4)Versions (21)Used By (0)

DateTime
========

[](#datetime)

An immutable class to deal with DateTime object used in `Noxem` systems. Works perfectly with [nette/forms](https://github.com/nette/forms) as Date, DateTime form's field.

[![Testing](https://camo.githubusercontent.com/f2006cca102863436c1c5596d47c77dfc45b8896210402a12b3ee5a520038cbb/68747470733a2f2f62616467656e2e6e65742f6769746875622f636865636b732f6e786d637a2f646174652d74696d652f6d61696e3f63616368653d333030)](https://github.com/nxmcz/date-time/actions)[![Coverage Status](https://camo.githubusercontent.com/d5955193bb188d3b4ff4a78d16927b84c355943f8b23ffa6304eae42e3f6d427/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6e786d637a2f646174652d74696d652f62616467652e7376673f6272616e63683d6d61696e)](https://coveralls.io/github/nxmcz/date-time?branch=main)[![Mutation testing badge](https://camo.githubusercontent.com/4418dd3be118cf8f4298623bf9adae50c1b38b1e5f24ca1a0aaac8c06434a9a6/68747470733a2f2f696d672e736869656c64732e696f2f656e64706f696e743f7374796c653d666c61742675726c3d687474707325334125324625324662616467652d6170692e737472796b65722d6d757461746f722e696f2532466769746875622e636f6d2532466e786d637a253246646174652d74696d652532466d61696e)](https://dashboard.stryker-mutator.io/reports/github.com/nxmcz/date-time/main)[![License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](https://github.com/nxmcz/date-time/blob/main/LICENSE)[![Latest Stable Version](https://camo.githubusercontent.com/52ae86d013f4ac5349c523faa5267ab0ade830fdcbadc1ca3ae623446b9ab9ca/687474703a2f2f706f7365722e707567782e6f72672f6e786d637a2f646174652d74696d652f76)](https://packagist.org/packages/nxmcz/date-time)[![Total Downloads](https://camo.githubusercontent.com/6b92fe489b4ff687e6098c0b5a507e0f2e1fb60e74fd58c6762da64da93adb2b/687474703a2f2f706f7365722e707567782e6f72672f6e786d637a2f646174652d74696d652f646f776e6c6f616473)](https://packagist.org/packages/nxmcz/date-time)[![License](https://camo.githubusercontent.com/bf013841a43ea67b18e0a5594b18e748c1baacb401a958ea73d724d3b60563b4/687474703a2f2f706f7365722e707567782e6f72672f6e786d637a2f646174652d74696d652f6c6963656e7365)](https://packagist.org/packages/nxmcz/date-time)

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

[](#requirements)

This library requires PHP 8.4 or later.

Usage
-----

[](#usage)

**Noxem\\DateTime\\DT**

Basic initialization of DT object. DT object is child of native DateTimeImmutable object with handles for modify date/time parts.

```
use Noxem\DateTime\DT;
use DateTime as NativeDateTime;

DT::create('now'); // 2022-08-07 12:00:00
(new DT('now')); // 2022-08-07 12:00:00
DT::create(1659866400); // 2022-08-07 12:00:00 initialize with timestamp

DT::create('2022-08-07 12:00:00'); // 2022-08-07 12:00:00
DT::createFromParts(2022, 8, 7, 12); // 2022-08-07 12:00:00
DT::createFromFormat(); // PHP's native method
DT::createFromInterface(new NativeDateTime());
DT::fromUTC("2022-08-07T12:00:00Z"); // 2022-08-07 14:00:00 in Europe/Prague

DT::getOrCreateInstance("2022-08-07 12:00:00"); // 2022-08-07 12:00:00
DT::getOrCreateInstance(DT::create("2022-08-08 12:00:00")); // 2022-08-08 12:00:00

$dt = DT::create('now'); // 2022-08-07 12:00:00
$dt->modify('+5 seconds'); // 2022-08-07 12:00:05
$dt->addDays(1); // 2022-08-08 12:00:00
$dt->subDays(1); // 2022-08-06 12:00:00
$dt->modifyDays(1); // ekvivalent to addDays(1)
```

Library supports casting object into HTML's native input types

```
use Noxem\DateTime\DT;

$object = DT::create('2022-08-07 12:00:00');
$object->toHtmlDate(); // 2022-08-07
$object->toHtmlMonth(); // 2022-08
$object->toHtmlWeek(); // 2022-W31
$object->toHtmlYear(); // 2022
```

Comparation:

```
DT::create('2022-08-07 12:00:00')
    ->areEquals(
        DT::create('2022-08-07 12:00:00')
        ->setTimezone('America/New_York')
    ); // FALSE

$ny = DT::create("2020-09-17 07:00:00")->assignTimezone("America/New_York");
$tokyo = DT::create("2020-09-17 20:00:00")->assignTimezone("Asia/Tokyo");
$ny->areEquals($tokyo); // TRUE
```

`isFuture(): bool` We operating with future?

```
$dt = DT::create('now');
echo $dt->modify('+1 seconds')->isFuture(); // TRUE
echo $dt->isFuture(); // FALSE
```

**Noxem\\DateTime\\Difference**

Difference formula can be imagined as `x = a - b`, where `a` is object which calling child method, formula example is `x = $b->difference($a)`Difference class is accessible with method: `DT::create()->difference(DT $suspect)`

```
$bigger = DT::create('2022-05-20 11:45:00');
$smaller = DT::create('2022-05-13 11:45:00');

$dt = $smaller->difference($bigger);
echo $dt->hours(); // 168.0
echo $dt->days(); // 7
echo $dt->solidWeeks(); // 1
echo $dt->minutes(); // 1440.0
echo $dt->msec(); // 86400000

$dt = $bigger->difference($smaller);
echo $dt->hours(); // -168.0
echo $dt->days(); // -7
echo $dt->solidWeeks(); // -1
echo $dt->minutes(); // -1440.0
echo $dt->msec(); // -86400000
```

Output of class is signed numbers. Where: positive numbers represent future, negative going back to future.

Sign of numberExampleDescription--5Past++5FutureMethod `withAbsolute()` ignores negative numbers on methods, difference will be always in positive numbers

```
$first = DT::create('2022-05-20 11:45:00');
$last = DT::create('2022-05-13 11:45:00');

$dt = $first->difference($last);
echo $dt->hours(); // -168.0
echo $dt->withAbsolute()->hours(); // +168.0
```

Method is also immutable.

**Noxem\\DateTime\\Overlap**

Next method is for compare two objects if overlap or not.

```
use Noxem\DateTime\Overlapping;

Overlapping::withTouching(
    DT::create('2021-05-06 09:00:00'),
    DT::create('2021-05-06 10:00:00'),
    DT::create('2021-05-06 10:00:00'),
    DT::create('2021-05-06 13:00:00'),
); // FALSE
```

Overlapping class handles only with one method (in future quantities increase). Description of interval overlap statements are presented in table below:

StepInterval visualisationResult**BORDERS**`            I           I            `After`     ██████ I           I            `FALSEStart touching`     ███████I           I            `FALSEStart inside`        ████I██         I            `TRUEInside start touching`            I███████████I███████     `TRUEEnclosing start touching`            I██████     I            `TRUEEnclosing`            I    █████  I            `TRUEEnclosing end touching`            I       ████I            `TRUEExact match`            I███████████I            `TRUEInside`        ████I███████████I██████      `TRUEInside end touching`        ████I███████████I            `TRUEEnd inside`            I       ████I████████████`TRUEEnd touching`            I           I████████████`FALSEBefore`            I           I  ███████████`FALSEException
---------

[](#exception)

Bad DateTime format throws an exception which is children of `InvalidArgumentException`

```
use Noxem\DateTime\DT;
use Noxem\DateTime\Exception\BadFormatException;

$dt = DT::create('foo'); // BadFormatException
```

###  Health Score

41

—

FairBetter than 88% of packages

Maintenance50

Moderate activity, may be stable

Popularity18

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity73

Established project with proven stability

 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 ~54 days

Recently: every ~163 days

Total

19

Last Release

384d ago

PHP version history (6 changes)v1.0.0PHP &gt;=8.0

v1.3.1PHP &gt;=8.1

v1.3.2PHP &gt;=8.1 &lt;8.3

v1.4.3PHP &gt;=8.1 &lt;=8.3

v1.4.4PHP &gt;=8.1 &lt;8.4

v1.4.5PHP &gt;=8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/de0c38352ad00555c6141fa8842b19600bea13b45264552e581fadafa5a2653c?d=identicon)[emololftw](/maintainers/emololftw)

---

Top Contributors

[![emololftw](https://avatars.githubusercontent.com/u/60448217?v=4)](https://github.com/emololftw "emololftw (115 commits)")

---

Tags

datedatetimephptimeimmutabledate-timedtnoxem

###  Code Quality

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[aeon-php/calendar

PHP type safe, immutable calendar library

2079.7M16](/packages/aeon-php-calendar)[qaribou/immutable.php

Immutable, highly-performant collections, well-suited for functional programming and memory-intensive applications.

344146.0k](/packages/qaribou-immutablephp)[innmind/immutable

Immutable PHP primitive wrappers

75218.0k73](/packages/innmind-immutable)[rtlopez/decimal

An object oriented immutable arbitrary-precision arithmetic library for PHP

27262.8k2](/packages/rtlopez-decimal)[aeon-php/calendar-holidays

Holidays calendar abstraction layer for Aeon Time management framework

14212.4k3](/packages/aeon-php-calendar-holidays)[andreas-glaser/php-helpers

A comprehensive collection of PHP utility functions for array manipulation, string operations, date handling, HTML generation, form building, validation, and more. Modern PHP 8.2+ library with full type safety.

1386.5k2](/packages/andreas-glaser-php-helpers)

PHPackages © 2026

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