PHPackages                             nyomanjyotisa/human-readable-time-diff - 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. nyomanjyotisa/human-readable-time-diff

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

nyomanjyotisa/human-readable-time-diff
======================================

A PHP package for converting timestamps into human-readable time differences

1.0.0(1y ago)00[1 issues](https://github.com/nyomanjyotisa/human-readable-time-diff/issues)MITPHPPHP &gt;=7.4

Since May 4Pushed 1y ago1 watchersCompare

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

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

Human Readable Time Difference
==============================

[](#human-readable-time-difference)

A PHP package for converting timestamps into human-readable time differences (e.g., "2 minutes ago", "3 hours ago", "1 day ago").

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

[](#requirements)

- PHP 7.4 or higher

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

[](#installation)

```
composer require nyomanjyotisa/human-readable-time-diff
```

Usage
-----

[](#usage)

### Basic Usage

[](#basic-usage)

```
use HumanReadableTimeDiff\TimeDifference;
use DateTime;

$timeDifference = new TimeDifference();
$timestamp = new DateTime('-2 hours');
echo $timeDifference->getDifference($timestamp); // Outputs: "2 hours ago"
```

### Using a Custom Reference Time

[](#using-a-custom-reference-time)

```
use HumanReadableTimeDiff\TimeDifference;
use DateTime;

$referenceTime = new DateTime('2023-01-01 12:00:00');
$timeDifference = new TimeDifference($referenceTime);
$timestamp = new DateTime('2023-01-01 10:00:00');
echo $timeDifference->getDifference($timestamp); // Outputs: "2 hours ago"
```

### Using Different Languages

[](#using-different-languages)

The package supports multiple languages out of the box:

```
use HumanReadableTimeDiff\TimeDifference;
use HumanReadableTimeDiff\TranslatedTimeFormatter;
use DateTime;

// Spanish
$formatter = new TranslatedTimeFormatter('es');
$timeDifference = new TimeDifference(null, $formatter);
$timestamp = new DateTime('-1 day');
echo $timeDifference->getDifference($timestamp); // Outputs: "1 día atrás"

// French
$formatter = new TranslatedTimeFormatter('fr');
$timeDifference = new TimeDifference(null, $formatter);
$timestamp = new DateTime('-2 hours');
echo $timeDifference->getDifference($timestamp); // Outputs: "il y a 2 heures"
```

### Supported Languages

[](#supported-languages)

The package supports 50+ locale codes. You can call `TranslationConfig::getAvailableLocales()` to retrieve the full list. Some examples include:

- en, id, es, fr, de, it, pt, ru, zh, ja, ko
- ar, hi, bn, tr, nl, pl, uk, vi, th, ms
- fa, ur, pa, gu, ta, te, kn, ml, mr, or, as
- ne, si, my, km, lo, bo, dz, ug, kk, ky, uz, tk
- az, ka, hy, he, yi, am, ti, om, so, sw, zu
- xh, st, tn, ts, ss, nr, nd, ve

For the complete list, refer to `TranslationConfig::getAvailableLocales()`.

### Creating Custom Formatters

[](#creating-custom-formatters)

You can create custom formatters by implementing the `TimeFormatterInterface`:

```
use HumanReadableTimeDiff\TimeFormatterInterface;

class CustomTimeFormatter implements TimeFormatterInterface
{
    public function formatSeconds(int $seconds): string
    {
        return $this->formatUnit($seconds, 'second');
    }

    // Implement other methods...

    private function formatUnit(int $value, string $unit): string
    {
        // Your custom formatting logic
    }
}
```

Testing
-------

[](#testing)

```
composer test
```

License
-------

[](#license)

This package is licensed under the MIT License.

Hire the Author
---------------

[](#hire-the-author)

Nyoman Jyotisa is a senior developer (PHP, JS, TS, Laravel, ReactJS, React Native, Next.js). Hire me at $20/hour.

Email:

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance52

Moderate activity, may be stable

Popularity0

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

 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

370d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/09a33b935338b07faa2e2a0da3bb4a894780d8679b46049efe14de6e835c1dcb?d=identicon)[nyomanjyotisa](/maintainers/nyomanjyotisa)

---

Top Contributors

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

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/nyomanjyotisa-human-readable-time-diff/health.svg)

```
[![Health](https://phpackages.com/badges/nyomanjyotisa-human-readable-time-diff/health.svg)](https://phpackages.com/packages/nyomanjyotisa-human-readable-time-diff)
```

###  Alternatives

[kris/laravel-form-builder

Laravel form builder - symfony like

1.7k2.2M45](/packages/kris-laravel-form-builder)

PHPackages © 2026

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