staspiv / knp-time-bundle
Knplabs 时间组件使你的日期看起来合理且描述性强
1.6.1
2016-05-10 16:53 UTC
Requires
- php: >=5.3.3
- symfony/config: ~2.3|~3.0
- symfony/dependency-injection: ~2.3|~3.0
- symfony/templating: ~2.3|~3.0
- symfony/translation: ~2.3|~3.0
Requires (Dev)
- phpunit/phpunit: ^4.8
Suggests
- symfony/twig-bundle: to use the Twig time_diff function
This package is not auto-updated.
Last update: 2024-09-14 17:43:03 UTC
README
此组件只做一件简单的事情:接受日期,并给你提供友好的“2小时前”类型的消息。哇!
Last edited {{ post.updatedAt|ago }} <-- Last edited 1 week ago -->
日期格式可以被翻译成任何语言,并且默认支持多种语言。
通过 Composer 安装
composer require knplabs/knp-time-bundle
配置
注册组件
<?php // app/AppKernel.php public function registerBundles() { $bundles = array( // ... new Knp\Bundle\TimeBundle\KnpTimeBundle(), ); // ... }
如果你还没有这样做,启用翻译组件
# app/config/config.yml framework: # ... translator: { fallback: '%locale%' } # uncomment this line if you see this line commented
用法
在 PHP 中!
<?php // Use the helper with Php echo $view['time']->diff($dateTime); // returns something like "3 minutes ago"
在 Twig 中!
{{ someDateTimeVariable|ago }} ... or use the equivalent function {{ time_diff(someDateTimeVariable) }}
测试
如果你想要运行测试,请确保你已经安装了开发依赖项。
./vendor/bin/phpunit
维护者
任何人都可以为这个仓库做出贡献(而且非常受欢迎!)。以下人员维护并可以合并到这个库中
- akovalyov
- weaverryan