staspiv/knp-time-bundle

Knplabs 时间组件使你的日期看起来合理且描述性强

安装: 67

依赖项: 0

建议者: 0

安全: 0

星标: 0

关注者: 2

分支: 105

类型:symfony-bundle

1.6.1 2016-05-10 16:53 UTC

README

Build Status

此组件只做一件简单的事情:接受日期,并给你提供友好的“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