Developed with love by KnpLabs Hire us for your project!
183

KnpTimeBundle

by KnpLabs

Provides helpers for time manipulation

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) }}

Note:

If you are using a different language code than two letters (en_US for example) then
should copy the TimeBundle's language files and rename the middle part according to your language:

from:
MyProject/vendor/bundles/Knp/Bundle/TimeBundle/Resources/translations/time.en.xliff
MyProject/vendor/bundles/Knp/Bundle/TimeBundle/Resources/translations/time.fr.xliff

to:
MyProject/app/Resources/translations/time.en_US.xliff
MyProject/app/Resources/translations/time.fr_FR.xliff

Don't forget to clear your cache afterwards.

Copyright (c) 2011 Knp Labs

The MIT license

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
  • Merge pull request #56 from weaverryan/master
    By pilot, 2 years ago
  • Merge pull request #57 from dhargitai/feature/hungarian-translation
    By pilot, 2 years ago
  • Add hungarian translation
    By dhargitai, 2 years ago
  • Putting some more advertising on top
    By weaverryan, 3 years ago
  • Updating the usage to show the cool ago filter
    By weaverryan, 3 years ago
  • Woh, removing some tabs!
    By weaverryan, 3 years ago
  • Removing unnecessary update line
    By weaverryan, 3 years ago
  • Merge pull request #55 from moldcraft/patch-1
    By pilot, 3 years ago
  • Added romanian translations
    By moldcraft, 3 years ago
  • Merge pull request #54 from seegno/pt-translations
    By pilot, 3 years ago
  • Added PT translations
    By fixe, 3 years ago
  • Merge pull request #43 from nurikabe/master
    By pilot, 3 years ago
  • Merge pull request #42 from jrobeson/patch-1
    By pilot, 3 years ago
  • Merge pull request #47 from sergeylunev/patch-1
    By pilot, 3 years ago
  • Merge pull request #46 from deep9/master
    By pilot, 3 years ago
  • Merge pull request #50 from thvd/patch-1
    By docteurklein, 4 years ago
  • Revert https://github.com/KnpLabs/KnpTimeBundle/commit/d2b0f7fc64e7128e6d8c0693d0b548045eec6db5
    By thvd, 4 years ago
  • Can install with Symfony 2.4
    By thvd, 4 years ago
  • Merge pull request #48 from kukulili-labs/master
    By pilot, 4 years ago
  • Add symfony 2.3 support
    By labs-scnm, 4 years ago
  • Update time.ru.xliff
    By sergeylunev, 4 years ago
  • Adding Czech translation
    By deep9, 4 years ago
  • Add slovenian translation - thanks Simon Horvat
    By mbontemps, 4 years ago
  • Remove rogue pipe
    By nurikabe, 4 years ago
  • Merge pull request #41 from luiges90/master
    By pilot, 4 years ago
  • Added Japanese translation
    By nurikabe, 4 years ago
  • remove symfony 2.0 installation instructions
    By jrobeson, 4 years ago
  • Merge remote-tracking branch 'upstream/master'
    By Peter Wong, 4 years ago
  • Fix chinese translation
    By Peter Wong, 4 years ago
  • Merge branch 'translation'
    By Peter Wong, 4 years ago