nowo-tech / relative-time-bundle
Format DateTime values as localized relative time strings (e.g. just now, 5 minutes ago) for Symfony and Twig.
Package info
github.com/nowo-tech/RelativeTimeBundle
Language:Shell
Type:symfony-bundle
pkg:composer/nowo-tech/relative-time-bundle
Fund package maintenance!
Requires
- php: >=8.2 <8.6
- symfony/config: ^7.4 || ^8.0
- symfony/dependency-injection: ^7.4 || ^8.0
- symfony/http-kernel: ^7.4 || ^8.0
- symfony/translation: ^7.4 || ^8.0
- symfony/translation-contracts: ^3.0
- twig/twig: ^3.8 || ^4.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- phpstan/extension-installer: ^1.4
- phpstan/phpstan: ^2.0
- phpstan/phpstan-symfony: ^2.0
- phpunit/phpunit: ^10.0
- rector/rector: ^2.0
- symfony/framework-bundle: ^7.4 || ^8.0
- symfony/yaml: ^7.4 || ^8.0
Suggests
- symfony/flex: For automatic recipe installation
- symfony/twig-bundle: To use the Twig filters and functions in a Symfony application
README
⭐ Found this useful? Install from Packagist and give it a star on GitHub.
Symfony bundle that formats a DateTime (or timestamp / date string) as a localized relative time string: just now, 5 minutes ago, in 2 hours, hace un momento, hace 3 días, and so on.
Features
- RelativeTimeFormatter service with past and future wording
- Twig filters/functions:
relative_timeandago - i18n catalogues for
en,es,it,fr,pt,de,nl(domainNowoRelativeTimeBundle) - Configurable
just_now_threshold_seconds,max_unit, locale and timezone defaults - App-level translation overrides (REQ-I18N-001)
Documentation
- Installation
- Configuration
- Usage
- Contributing
- Changelog
- Upgrading
- Release
- Security
- Engram
- Spec-driven development
- GitHub Spec Kit
Additional documentation
- GitHub Actions CI requirements
- Code of Conduct
- Demo (Symfony 7 & 8) — run
make -C demo up-symfony8from the bundle root. - Demo with FrankenPHP (development and production)
Quick example
use Nowo\RelativeTimeBundle\Service\RelativeTimeFormatter; public function __construct(private RelativeTimeFormatter $relativeTime) {} public function label(\DateTimeInterface $createdAt): string { return $this->relativeTime->format($createdAt, 'es'); // → "hace 5 minutos" }
{{ entity.createdAt|relative_time }}
{{ entity.createdAt|ago('es') }}
{{ relative_time(entity.publishedAt, 'fr') }}
Requirements
- PHP >= 8.2, < 8.6
- Symfony 7.4+ or 8.x (
symfony/translation, Twig) - Twig 3.8+ or 4.x
Tests and coverage
| Language | Lines (approx.) | Command |
|---|---|---|
| PHP | ~100% | make test-coverage |
| TypeScript | N/A | — |
| Python | N/A | — |
make test
make test-coverage
make validate-translations
make release-check
PHP coverage target is ~100% (currently ~100%; see Release).
Demo
make -C demo up-symfony8
# Demo started at: http://localhost:8008
FrankenPHP worker mode for production demos is documented in DEMO-FRANKENPHP.md.
Version policy
The Composer package name is nowo-tech/relative-time-bundle. Source code and issues are in the GitHub repository nowo-tech/RelativeTimeBundle.
We follow Semantic Versioning. See Changelog for release notes. Security support by major version is described in the Security policy.
License
MIT. See LICENSE.