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

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 many 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:

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 #129 from KnpLabs/bump-deps
    By web-flow, 8 months ago
  • Adding IntegrationTest
    By weaverryan, 8 months ago
  • bumping php & symfony version dependencies and making code updates
    By weaverryan, 8 months ago
  • Merge pull request #127 from zaggi-iwnl/master
    By web-flow, 8 months ago
  • use namespaced twig classes
    By web-flow, 9 months ago
  • use namespaced Twig classes
    By web-flow, 9 months ago
  • Merge pull request #124 from svenluijten/patch-1
    By web-flow, 9 months ago
  • Fix typo
    By web-flow, 9 months ago
  • Merge pull request #123 from KnpLabs/weaverryan-patch-1
    By web-flow, 9 months ago
  • removing support for most obsolete versions
    By web-flow, 9 months ago
  • Merge pull request #121 from tacman/patch-1
    By web-flow, 9 months ago
  • Allow Symfony 5
    By web-flow, 9 months ago
  • Merge pull request #117 from cb8/transchoice
    By web-flow, 1 year ago
  • Use transChoice for Symfony <4.2
    By cb8, 1 year ago
  • Merge pull request #111 from dirkkredler/fix-symfony-4-2-transchoice-deprecation
    By web-flow, 1 year ago
  • Fix symfony 4.2 transChoice deprecation
    By , 1 year ago
  • Merge pull request #103 from michalkurzeja/sf4-compat
    By web-flow, 2 years ago
  • [Travis] Switched SF 4.0.* to beta channel
    By michalkurzeja, 2 years ago
  • Removed bullshit test
    By michalkurzeja, 2 years ago
  • SF4 compatibility update
    By michalkurzeja, 2 years ago
  • Merge pull request #101 from sergiu-popa/master
    By web-flow, 2 years ago
  • Fix romanian translation of minute (singular)
    By web-flow, 2 years ago
  • Merge pull request #99 from KnpLabs/doc/update-maintainers
    By web-flow, 3 years ago
  • Added a maintainer in the README.md
    By NicolasNSSM, 3 years ago
  • Merge pull request #95 from garak/patch-1
    By web-flow, 3 years ago
  • Merge pull request #97 from dfridrich/patch-1
    By web-flow, 3 years ago
  • Add Slovak translation
    By web-flow, 3 years ago
  • Add .gitattributes
    By web-flow, 3 years ago
  • Merge pull request #94 from marcu87/master
    By web-flow, 3 years ago
  • added Esperanto translation
    By marcu87, 3 years ago