PHPackages                             amaccis/datetai - 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. amaccis/datetai

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

amaccis/datetai
===============

A PHP library including a set of tools for handling the TAI time standard with DateTime and DateTimeImmutable instances.

0.9.0(3y ago)09MITPHPPHP ^8.1.7

Since Mar 19Pushed 3y agoCompare

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

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

DateTai
=======

[](#datetai)

[![PHP Version](https://camo.githubusercontent.com/ab161bcc51d48cd7a5215aec306ff9cc8895971fd2a955083a1e4fee7afa0b4a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545382e312e372d626c75652e737667)](https://img.shields.io/badge/php-%5E8.1.7-blue.svg)[![CI workflow](https://github.com/amaccis/datetai/actions/workflows/ci.yml/badge.svg)](https://github.com/amaccis/datetai/actions/workflows/ci.yml/badge.svg)

A PHP library including a set of tools for handling the TAI time standard with DateTime and DateTimeImmutable instances.

For a basic knowledge of TAI [read this](https://en.wikipedia.org/wiki/International_Atomic_Time). For a basic knowledge of TAI's external formats, that is TAI64, TAI64N and TAI64NA, [read this](https://cr.yp.to/libtai/tai64.html). Finally, for a basic knowledge of leap seconds [read this](https://maia.usno.navy.mil/information/what-is-a-leap-second).

*Since DateTimeInterface does not handle nanoseconds, TAI64N format is partially supported by this library and the values are always rounded to microseconds. For the same reason TAI64NA format is not currently supported.*

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

[](#installation)

The library is available as a package on [Packagist](http://packagist.org/packages/amaccis/datetai), so you can install it using [Composer](http://getcomposer.org)

```
composer require amaccis/datetai
```

Basic usage
-----------

[](#basic-usage)

### TAI/UTC conversion

[](#taiutc-conversion)

```
    use Amaccis\DateTai\DateTai;
    use DateTime;
    use DateTimeImmutable;

    $taiDateTime = new DateTime('1992-06-02 08:07:09');
    $utcDateTime = DateTai::convertTaiIntoUtc($taiDateTime);
    var_dump($utcDateTime->format('Y-m-d H:i:s')); // 1992-06-02 08:06:43

    $taiDateTimeImmutable = new DateTimeImmutable('1992-06-02 08:07:09');
    $utcDateTimeImmutable = DateTai::convertTaiIntoUtc($taiDateTimeImmutable);
    var_dump($utcDateTimeImmutable->format('Y-m-d H:i:s')); // 1992-06-02 08:06:43
```

### UTC/TAI conversion

[](#utctai-conversion)

```
    use Amaccis\DateTai\DateTai;
    use DateTime;
    use DateTimeImmutable;

    $utcDateTime = new DateTime('1992-06-02 08:06:43');
    $taiDateTime = DateTai::convertUtcIntoTai($utcDateTime);
    var_dump($taiDateTime->format('Y-m-d H:i:s')); // 1992-06-02 08:07:09

    $utcDateTimeImmutable = new DateTimeImmutable('1992-06-02 08:06:43');
    $taiDateTimeImmutable = DateTai::convertUtcIntoTai($utcDateTimeImmutable);
    var_dump($taiDateTimeImmutable->format('Y-m-d H:i:s')); // 1992-06-02 08:07:09
```

### Format a DateTimeInterface using an external TAI format

[](#format-a-datetimeinterface-using-an-external-tai-format)

```
    use Amaccis\DateTai\DateTai;
    use Amaccis\DateTai\Enum\ExternalTaiFormatEnum;
    use DateTime;

    $dateTime = new DateTime('1992-06-02 08:07:09');
    $externalTai64Format = DateTai::formatAsExternalTaiFormat($dateTime, ExternalTaiFormatEnum::TAI64);
    var_dump($externalTai64Format); // 400000002a2b2c2d
```

```
    use Amaccis\DateTai\DateTai;
    use Amaccis\DateTai\Enum\ExternalTaiFormatEnum;
    use DateTimeImmutable;

    $dateTimeImmutable = new DateTimeImmutable('1992-06-02 08:07:09.389984500');
    $externalTai64NFormat = DateTai::formatAsExternalTaiFormat($dateTimeImmutable, ExternalTaiFormatEnum::TAI64N);
    var_dump($externalTai64NFormat); // 400000002a2b2c2d173eaf00
```

### Create a DateTimeInterface from a TAI label, formatted using an external TAI format

[](#create-a-datetimeinterface-from-a-tai-label-formatted-using-an-external-tai-format)

```
    use Amaccis\DateTai\DateTai;
    use Amaccis\DateTai\Enum\DateTimeInterfaceEnum;
    use Amaccis\DateTai\Enum\ExternalTaiFormatEnum;

    $externalTai64Format = "400000002a2b2c2d";
    $dateTime = DateTai::createFromExternalTaiFormat(ExternalTaiFormatEnum::TAI64, $externalTai64Format, DateTimeInterfaceEnum::DateTime);
    var_dump($dateTimeImmutable->format('Y-m-d H:i:s')); // 1992-06-02 08:07:09
```

```
    use Amaccis\DateTai\DateTai;
    use Amaccis\DateTai\Enum\DateTimeInterfaceEnum;
    use Amaccis\DateTai\Enum\ExternalTaiFormatEnum;

    $externalTai64NFormat = "400000002a2b2c2d173eb0f4";
    $dateTimeImmutable = DateTai::createFromExternalTaiFormat(ExternalTaiFormatEnum::TAI64N, $externalTai64NFormat, DateTimeInterfaceEnum::DateTimeImmutable);
    var_dump($dateTimeImmutable->format('Y-m-d H:i:s.u')); // 1992-06-02 08:07:09.389985
```

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity45

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

Total

2

Last Release

1152d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/15266603?v=4)[Andrea Maccis](/maintainers/amaccis)[@amaccis](https://github.com/amaccis)

---

Top Contributors

[![amaccis](https://avatars.githubusercontent.com/u/15266603?v=4)](https://github.com/amaccis "amaccis (10 commits)")

---

Tags

datetimetimedatedatetimeimmutableTAI64TAI64NTAI64NAtai

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/amaccis-datetai/health.svg)

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

###  Alternatives

[league/period

Time range API for PHP

7335.4M21](/packages/league-period)[brick/date-time

Date and time library

3623.3M61](/packages/brick-date-time)[aeon-php/calendar

PHP type safe, immutable calendar library

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

Date/Calendar recursion library.

5261.0M5](/packages/tplaner-when)[kartik-v/php-date-formatter

A Javascript datetime formatting and manipulation library using PHP date-time formats.

461.5M3](/packages/kartik-v-php-date-formatter)[dater/dater

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

14282.3k](/packages/dater-dater)

PHPackages © 2026

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