nehlsen/time-formatter-bundle

Small Utility to format remaining time of something into a human-readable form

Installs: 2

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 1

Type:symfony-bundle

pkg:composer/nehlsen/time-formatter-bundle

2.0.1 2024-09-28 08:22 UTC

This package is auto-updated.

Last update: 2025-09-28 11:29:03 UTC


README

Small Utility class to format remaining time of something into a human-readable form.

Example

Given Milk having a bestBefore Timestamp, we can calculate its remaining lifetime like so

/** @var Milk $myMilk */
$myMilk = $fridge->getMyMilk();
/** @var \DateTimeImmutable $bestBefore */
$bestBefore = $myMilk->getBestoBefore(); 

$secondsUntilBad = $bestBefore->getTimestamp() - time();

$formatter = new \nehlsen\TimeFormatterBundle\TimeFormatter\TimeFormatter();
$formattedBestBefore = $formatter->format($secondsUntilBad);
// $formattedBestBefore == '3 Days 1 Hour 17 Seconds';

For a range of options and examples see example1.php

Installation

  1. Require the library
    composer require nehlsen/time-formatter
  2. For the translations to work, the provided files can be used, copied, linked. But they are not enabled automatically.