Provide a time helper to Symfony2 projects.
INSTALLATION
Composer
composer require knplabs/knp-time-bundle
composer --dev update knplabs/knp-time-bundle
Submodule
Add it to your Symfony Project using git:
git submodule add git://github.com/KnpLabs/KnpTimeBundle.git MyProject/vendor/bundles/Knp/Bundle/TimeBundle
Deps
[KnpTimeBundle]
git=https://github.com/KnpLabs/KnpTimeBundle.git
target=bundles/Knp/Bundle/TimeBundle
Register the namespaces:
<?php
// app/autoload.php
$loader->registerNamespaces(array(
// ...
'Knp\Bundle' => __DIR__.'/../vendor/bundles',
// ...
));
CONFIGURATION
Register the bundle:
<?php
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new Knp\Bundle\TimeBundle\KnpTimeBundle(),
);
// ...
}
Enable the helper in your config.yml:
# app/config/config.yml
knp_time: ~ # Enable the helper for use in templates
Also enable translation component if you haven't do it yet.
# app/config/config.yml
framework:
# ...
translator: { fallback: %locale% } # uncomment this line if you see this line commented
USAGE
<?php
// Use the helper with Php
echo $view['time']->diff($dateTime); // returns something like "3 minutes ago"
// Use the helper with twig
{{ time_diff(DateTimeObject) }}
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.
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 #41 from luiges90/master
By pilot, 9 days ago
-
Merge pull request #41 from luiges90/master
By pilot, 9 days ago
-
Merge pull request #41 from luiges90/master
By pilot, 9 days ago
-
Merge pull request #41 from luiges90/master
By pilot, 9 days ago
-
Merge pull request #41 from luiges90/master
By pilot, 9 days ago
-
Merge pull request #41 from luiges90/master
By pilot, 9 days ago
-
Merge pull request #41 from luiges90/master
By pilot, 9 days ago
-
Merge pull request #41 from luiges90/master
By pilot, 9 days ago
-
Merge pull request #41 from luiges90/master
By pilot, 9 days ago
-
Merge pull request #41 from luiges90/master
By pilot, 9 days ago
-
Merge pull request #41 from luiges90/master
By pilot, 9 days ago
-
Merge pull request #41 from luiges90/master
By pilot, 9 days ago
-
Merge pull request #41 from luiges90/master
By pilot, 9 days ago
-
Merge pull request #41 from luiges90/master
By pilot, 9 days ago
-
Merge pull request #41 from luiges90/master
By pilot, 9 days ago
-
Merge pull request #41 from luiges90/master
By pilot, 9 days ago
-
Merge pull request #41 from luiges90/master
By pilot, 9 days ago
-
Merge pull request #41 from luiges90/master
By pilot, 9 days ago
-
Merge pull request #41 from luiges90/master
By pilot, 9 days ago
-
Merge pull request #41 from luiges90/master
By pilot, 9 days ago
-
Merge pull request #41 from luiges90/master
By pilot, 9 days ago
-
Merge pull request #41 from luiges90/master
By pilot, 9 days ago
-
Merge pull request #41 from luiges90/master
By pilot, 9 days ago
-
Merge pull request #41 from luiges90/master
By pilot, 9 days ago
-
Merge pull request #41 from luiges90/master
By pilot, 9 days ago
-
Merge pull request #41 from luiges90/master
By pilot, 9 days ago
-
Merge pull request #41 from luiges90/master
By pilot, 9 days ago
-
Merge pull request #41 from luiges90/master
By pilot, 9 days ago
-
Merge pull request #41 from luiges90/master
By pilot, 9 days ago
-
Merge pull request #41 from luiges90/master
By pilot, 9 days ago
