Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Relative Time Bundle

CI Packagist Version Packagist Downloads License PHP Symfony GitHub stars Coverage

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_time and ago
  • i18n catalogues for en, es, it, fr, pt, de, nl (domain NowoRelativeTimeBundle)
  • Configurable just_now_threshold_seconds, max_unit, locale and timezone defaults
  • App-level translation overrides (REQ-I18N-001)

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

Demo

make -C demo up-symfony8
# Demo started at: http://localhost:8008

FrankenPHP worker mode for production demos is documented in DEMO-FRANKENPHP.md.

Documentation

Additional documentation

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

CI enforces PHP coverage at 100%.

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.

About

Format DateTime values as localized relative time strings (e.g. just now, 5 minutes ago) for Symfony and Twig.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages