承接 smirik/php-datetime-ago 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

smirik/php-datetime-ago

Composer 安装命令:

composer require smirik/php-datetime-ago

包简介

How much time ago in text format

README 文档

README

This library helps to format the date/time interval into text.

Examples

Condition Text
Now now
Less than an hour xx minutes ago
Between 1 and 2 hours 1 hour ago
Between 2 and 24 hours xx hours ago
Between 1 and 2 days 1 day ago
Between 2 and 6 days xx days ago
7 or more days ago xx weeks ago
30 or more days ago xx months ago
365 or more days ago xx years ago

Notice that not every translator supports weeks, months and years

Usage

DateTimeAgo class has public method get. It accepts 1 required argument (\DateTime object) and 1 optional (reference date. If it is null, current time is used).

<?php
    $date_ago = new \Smirik\PHPDateTimeAgo\DateTimeAgo();
    $date_ago->get(new \DateTime('-24 hours')); /* returns "1 day ago" */
    $date_ago->get(new \DateTime('-69 minutes')); /* returns "1 hour ago" */
    $date_ago->get(new \DateTime('-100 minutes')); /* returns "2 hours ago" */
    $date_ago->get(new \DateTime('-155 minutes')); /* returns "3 hours ago" */

Russian translation:

<?php
    $date_ago = new \Smirik\PHPDateTimeAgo\DateTimeAgo(new \Smirik\PHPDateTimeAgo\TextTranslator\RussianTextTranslator());
    $date_ago->get(new \DateTime('-24 hours')); /* returns "1 день назад" */
    $date_ago->get(new \DateTime('-69 minutes')); /* returns "1 час назад" */
    $date_ago->get(new \DateTime('-100 minutes')); /* returns "2 часа назад" */
    $date_ago->get(new \DateTime('-155 minutes')); /* returns "3 часа назад" */

Customization

Date formatter for more than 6 days

<?php
    ...
    $date_ago->setFormat('d.m.Y H:i:s');

This setup date in format 01.01.2001 22:52:12.

Custom translator

The DateTimeAgo constructor accept TextTranslator file as the first argument. By default EnglishTextTranslator is provided. You can add your custom translator to this constructor. Just make sure that your class implements Smirik\PHPDateTimeAgo\TextTranslator\TextTranslatorInterface. There is also standard way for translations based on pluralization procedure. The methods are already implemented for any language in AbstractTextTranslator class. English & Russian samples are already included in this package. You can also change the translator after creation:

<?php
    ...
    $date_ago->setTextTranslator(new \Smirik\PHPDateTimeAgo\TextTranslator\RussianTextTranslator());

Implementation

Tests

Most parts of the code are tested via phpspec. To run the tests clone the repository and run

$ php bin/phpspec run

Development workflow

  • In order to keep git versioning accurate please use git-flow pattern.
  • So all pull requests except hotfix should go to the develop branch.
  • Hotfix should go to both development branches: develop & master at the same time.

Contribution

Any contribution is welcome.

Acknowledgements

smirik/php-datetime-ago 适用场景与选型建议

smirik/php-datetime-ago 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 158.01k 次下载、GitHub Stars 达 22, 最近一次更新时间为 2013 年 07 月 22 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 smirik/php-datetime-ago 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 smirik/php-datetime-ago 我们能提供哪些服务?
定制开发 / 二次开发

基于 smirik/php-datetime-ago 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 158.01k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 22
  • 点击次数: 29
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 22
  • Watchers: 3
  • Forks: 5
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2013-07-22