nehlsen / time-formatter-bundle
Small Utility to format remaining time of something into a human-readable form
Installs: 1
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 1
Type:symfony-bundle
Requires
- php: ^8.3
- symfony/config: ^6.3 || ^7.0
- symfony/dependency-injection: ^6.3 || ^7.0
- symfony/http-kernel: ^6.3 || ^7.0
- symfony/options-resolver: ^6.3 || ^7.0
- symfony/translation: ^6.3 || ^7.0
- symfony/translation-contracts: ^2.5 || ^3.0
Requires (Dev)
- ergebnis/composer-normalize: ^2.42
- friendsofphp/php-cs-fixer: ^3.46
- jangregor/phpstan-prophecy: ^1.0
- phpspec/prophecy-phpunit: ^2.0
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^10.5
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
- Require the library
composer require nehlsen/time-formatter
- For the translations to work, the provided files can be used, copied, linked. But they are not enabled automatically.