⭐ 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.
- 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)
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') }}- PHP >= 8.2, < 8.6
- Symfony 7.4+ or 8.x (
symfony/translation, Twig) - Twig 3.8+ or 4.x
make -C demo up-symfony8
# Demo started at: http://localhost:8008FrankenPHP worker mode for production demos is documented in DEMO-FRANKENPHP.md.
- Installation
- Configuration
- Usage
- Contributing
- Code of Conduct
- Changelog
- Upgrading
- Release
- Security
- Engram
- Spec-driven development
- GitHub Spec Kit
- GitHub Actions CI requirements
- Demo (Symfony 7 & 8) — run
make -C demo up-symfony8from the bundle root. - Demo with FrankenPHP (development and production)
| 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-checkCI enforces PHP coverage at 100%.
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.
MIT. See LICENSE.