Skip to content
Provides helpers for time manipulation
PHP
Branch: master
Clone or download
nicolasmure Merge pull request #117 from cb8/transchoice
Use transChoice for Symfony <4.2
Latest commit d8464f1 Apr 19, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
DependencyInjection Change Knplabs to Knp. BC break before Symfony2 release. Jul 3, 2011
Resources Fix romanian translation of minute (singular) Oct 19, 2017
Templating/Helper Add DateTimeImmutable support Jul 11, 2016
Tests Removed bullshit test Nov 18, 2017
Twig/Extension Updates twig extension to work with twig 1.12-2.0 Oct 6, 2015
.gitattributes Add .gitattributes Mar 5, 2017
.gitignore Add phpunit config Nov 11, 2015
.travis.yml [Travis] Switched SF 4.0.* to beta channel Nov 18, 2017
DateTimeFormatter.php Use transChoice for Symfony <4.2 Mar 21, 2019
KnpTimeBundle.php Change Knplabs to Knp. BC break before Symfony2 release. Jul 3, 2011
LICENSE Change Knplabs to Knp. BC break before Symfony2 release. Jul 3, 2011
README.md
composer.json SF4 compatibility update Nov 18, 2017
phpunit.xml.dist Add phpunit config Nov 11, 2015

README.md

Friendly ago dates ("5 minutes ago")!

This bundle does one simple job: takes dates and gives you friendly "2 hours ago"-type messages. Woh!

Last edited {{ post.updatedAt|ago }}
<-- Last edited 1 week ago -->

The date formatted can be translated into any language, and may are supported out of the box.

INSTALLATION via Composer

composer require knplabs/knp-time-bundle

CONFIGURATION

Register the bundle:

<?php
// app/AppKernel.php
public function registerBundles()
{
    $bundles = array(
        // ...
        new Knp\Bundle\TimeBundle\KnpTimeBundle(),
    );
    // ...
}

Enable the translation component if you haven't already done it:

# app/config/config.yml
framework:
    # ...
    translator:      { fallback: '%locale%' } # uncomment this line if you see this line commented

USAGE

In PHP!

<?php
// Use the helper with Php
echo $view['time']->diff($dateTime); // returns something like "3 minutes ago"

In Twig!

{{ someDateTimeVariable|ago }}
... or use the equivalent function
{{ time_diff(someDateTimeVariable) }}

TESTS

If you want to run tests, please check that you have installed dev dependencies.

./vendor/bin/phpunit

Maintainers

Anyone can contribute to this repository (and it's warmly welcomed!). The following people maintain and can merge into this library:

You can’t perform that action at this time.