PHPackages                             upyx/php-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. upyx/php-time

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

upyx/php-time
=============

Object oriented representation of time and time only (without date, timezone or something else).

1.0.0(6y ago)2722↑200%MITPHPPHP ^7.2CI failing

Since Dec 12Pushed 6y ago1 watchersCompare

[ Source](https://github.com/upyx/php-time)[ Packagist](https://packagist.org/packages/upyx/php-time)[ RSS](/packages/upyx-php-time/feed)WikiDiscussions master Synced 2w ago

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

upyx/php-time
=============

[](#upyxphp-time)

[![Source Code](https://camo.githubusercontent.com/fd5eabdcfd35d214c37b1a9dee62d51b471a15bcc1b7281717b35d82b3b30d42/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f736f757263652d757079782f7068702d2d74696d652d626c75652e7376673f7374796c653d666c6174)](https://github.com/upyx/php-time)[![Latest Version](https://camo.githubusercontent.com/40323b4095f744ece9e7e5482b7ca0d3f972662b5b2fe734fac4c3efcce66dbb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f757079782f7068702d74696d652e7376673f7374796c653d666c6174266c6162656c3d72656c65617365)](https://packagist.org/packages/upyx/php-time)[![Software License](https://camo.githubusercontent.com/ac79a905e86920913c85e9eeebcd6798d288adf27b47b30e1209f242c7e185b3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f757079782f7068702d74696d652e7376673f7374796c653d666c6174)](https://github.com/upyx/php-time/blob/master/LICENSE)[![PHP Version](https://camo.githubusercontent.com/8766968637070e1bbd49548a1a51c0c21909693fe168958c6c29825600aa48aa/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f757079782f7068702d74696d652e7376673f7374796c653d666c6174)](https://php.net)[![Build Status](https://camo.githubusercontent.com/290d471fae3302661fdfd5ca68f952e1e9e7335f039f9f4415c66334db61116b/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f757079782f7068702d74696d652f6d61737465722e7376673f7374796c653d666c6174)](https://travis-ci.org/upyx/php-time)[![Coverage Status](https://camo.githubusercontent.com/9153b05408e052fc6f7dec71094d3b695ae324b610c145001791e558991e421d/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f6769746875622f757079782f7068702d74696d652f6d61737465722e7376673f7374796c653d666c6174)](https://coveralls.io/r/upyx/php-time?branch=master)[![Total Downloads](https://camo.githubusercontent.com/a18959f4a4ba4fc8770bf1ee4a98f81db776865ab155500a1c6059573108d1a3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f757079782f7068702d74696d652e7376673f7374796c653d666c617426636f6c6f72423d6d656469756d76696f6c6574726564)](https://packagist.org/packages/upyx/php-time)

Object oriented representation of time with microseconds. It like o'clock time without date, timezone or something else but cyclical for 24 hours.

Why not DateTime/DateTimeImmutable from standard library?
---------------------------------------------------------

[](#why-not-datetimedatetimeimmutable-from-standard-library)

It is for different purposes. DateTime uses for calendar (linear) time through ages. But this library is intended to represent periodical time day by day.

Let's look closer. Noon in Tokyo and noon in New York are different times in the world. Noon on the 1st of December and noon on the 2nd December are different times. But noon is still 12 **o'clock**.

It is still possible to use DateTime for o'clock time, but it has some disadvantages. Firstly, it is curly because it needs some "zero-date". Secondary, it is difficult to compare and calculate because of changing dates. Thirdly, it is buggy because of timezone conversions. Fourthly, it confuses with the DateTime type used as calendar time.

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

[](#installation)

The preferred method of installation is via [Composer](https://getcomposer.org/). Run the following command to install the package and add it as a requirement to your project's `composer.json`:

```
composer require upyx/php-time
```

Usage
-----

[](#usage)

LocalTime can be created in three ways:

```
use Upyx\PhpTime\LocalTime;
$time1 = new LocalTime(10, 20, 30, 40000);
$time2 = LocalTime::fromDateTime(new DateTimeImmutable('10:20:30'));
$time3 = LocalTime::fromMicroseconds(3600000000);
```

There are "add" and "subtract" methods:

```
use Upyx\PhpTime\LocalTime;
$time1 = new LocalTime(10, 0);
$time2 = new LocalTime(13, 0);
var_dump($time1->cyclicAdd($time2)); // 23:00:00.000000
var_dump($time2->cyclicSubtract($time1)); // 03:00:00.000000
var_dump($time1->cyclicSubtract($time2)); // 21:00:00.000000
```

As time is periodical, there are two distances between two times in both directions. There is a method to calculate the smallest distance between ones:

```
use Upyx\PhpTime\LocalTime;
$time1 = new LocalTime(2, 0);
$time2 = new LocalTime(12, 0);
$time3 = new LocalTime(22, 0);
var_dump($time1->calcDistance($time2)); // 10:00:00.000000
var_dump($time2->calcDistance($time3)); // 10:00:00.000000
var_dump($time1->calcDistance($time3)); // 04:00:00.000000
```

It is possible to use comparison operators. The smallest value is "00:00:00.000000", the greatest one is "23:59:59.999999".

```
use Upyx\PhpTime\LocalTime;
$time1 = new LocalTime(10, 0);
$time2 = new LocalTime(13, 0);
var_dump($time1 < $time2); // true
var_dump($time1  $time2); // false
var_dump($time1 >= $time2); // false
var_dump($time1  $time2); // -1
```

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

[](#contributing)

If you have a question, feel free to create an issue. If you would like to send me a pull request, please create an issue first.

Copyright and License
---------------------

[](#copyright-and-license)

The upyx/php-time library is copyright © Sergey Rabochiy and licensed for use under the MIT License (MIT). Please see [LICENSE](https://github.com/upyx/php-time/blob/master/LICENSE) for more information.

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity52

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

Unknown

Total

1

Last Release

2384d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0700d9b86802871c7130fc67198af4d38b21341caae3fff5bca9d9fb3f846a65?d=identicon)[upyx](/maintainers/upyx)

---

Top Contributors

[![upyx](https://avatars.githubusercontent.com/u/6064612?v=4)](https://github.com/upyx "upyx (1 commits)")

---

Tags

libraryphptimetime

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/upyx-php-time/health.svg)

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

###  Alternatives

[pocketmine/pocketmine-mp

A server software for Minecraft: Bedrock Edition written in PHP

3.5k77.4k88](/packages/pocketmine-pocketmine-mp)[symfony/clock

Decouples applications from the system clock

434192.7M336](/packages/symfony-clock)[knplabs/knp-time-bundle

Making your dates and durations look sensible and descriptive

6239.3M51](/packages/knplabs-knp-time-bundle)[league/period

Time range API for PHP

7335.7M22](/packages/league-period)[wapmorgan/morphos

A morphological solution for Russian and English language written completely in PHP. Provides classes to inflect personal names, geographical names, decline and pluralize nouns, generate cardinal and ordinal numerals, spell out money amounts and time.

8261.3M7](/packages/wapmorgan-morphos)[brick/date-time

Date and time library

3623.6M94](/packages/brick-date-time)

PHPackages © 2026

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