salernolabs/relative-time 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

salernolabs/relative-time

Composer 安装命令:

composer require salernolabs/relative-time

包简介

Library for building relative time strings in PHP.

README 文档

README

Latest Stable Version License Build Status

Library for building relative time strings in PHP.

Usage

Installation

First include this project with composer

composer require salernolabs/relative-time

Formatting Time

Then run the formatter on a DateTime object.

$formatter = new \SalernoLabs\RelativeTime\Formatter();
$relativeTime = $formatter->getRelativeTime(new \DateTime('-47 minutes'));
echo $relativeTime;

This would output '47 minutes ago'. The formatter will also go forward as well so if you put in '+47 minutes' it will say "47 mintues from now".

Examples of Time Reformatting

This library will also give short-hand conversational outputs for some values. For example:

Time Modification Output
-5 minutes just now
+5 minutes momentarily
-1 minute about a minute ago
+1 minute about a minute from now
-1 hour about an hour ago
+1 hour about an hour from now
-1 day yesterday
+1 day tomorrow

And actual numbers for other times, for example:

Time Modification Output
-45 seconds 45 seconds ago
-45 minutes 45 minutes ago
-7 hours 7 hours ago
-3 years 3 years ago

HTML5 Tags

You can easily wrap the output in an html5 time tag by using the getRelativeTimeTag function.

$formatter = new \SalernoLabs\RelativeTime\Formatter();
$relativeTime = $formatter->getRelativeTimeTag(new \DateTime('-47 minutes'));
echo $relativeTime;

This would output:

<time title="April 14th, 2017 - 4:14PM EDT">47 minutes ago</time>

Relative Time Clock

The relative time clock can give you a textual representation of a time of day.

$clock = new \SalernoLabs\RelativeTime\Clock();

$time = $clock
    ->setTime(new \DateTime('7:47'))
    ->getTime();

echo $time; // a quarter to eight o'clock

Examples of Relative Clock Output

Input Time Output
1:00 one o'clock
5:03 five o'clock,
2:07 almost ten after two o'clock,
3:10 ten after three o'clock
4:15 quarter after four o'clock
6:22 almost half past six o'clock
7:32 half past seven o'clock
8:44 almost a quarter to nine o'clock
9:45 a quarter to ten o'clock
11:55 almost twelve o'clock
12:00 twelve o'clock,
12:59 almost one o'clock
12:45 a quarter to one o'clock
12:43 almost a quarter to one o'clock

salernolabs/relative-time 适用场景与选型建议

salernolabs/relative-time 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.3k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2017 年 04 月 28 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「timestamp」 「Relative Time」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

围绕 salernolabs/relative-time 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 4.3k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 11
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-04-28