rm/dateinterval
Composer 安装命令:
composer require rm/dateinterval
包简介
DateInterval extension
README 文档
README
Simple library for manipulating with date intervals in PHP.
Requirements
- PHP 7.0
Installation
$ composer require rm/dateinterval
Features
Extends creation possibility
namespace RM\DateInterval; new DateInterval; // 0 seconds new DateInterval('PT0S'); // 0 seconds new DateInterval(new \DateInterval('PT0S')); // 0 seconds new DateInterval('-P1D'); // - 1 day new DateInterval('+2 minutes'); new DateInterval(10); // 10 seconds new DateInterval(-1000); // -1000 seconds new DateInterval(5.5); // 6 seconds
Adding/Subtraction
Allowing summarize multiple intervals into one.
$interval = new \RM\DateInterval; foreach ([ 'PT10S', // 0:10 'PT13M14S', // 13:24 'PT3M3S', // 16:27 'PT4M58S', // 21:25 ] as $data) { $interval->add($data); } echo $interval->format('%i:%s'); // '21:25'
Convert to seconds
Usable for comparing.
(new \RM\DateInterval('+1 day'))->toSeconds(); // int(86400)
Generate string
Generating standardized string, for storing interval to database.
$now = new DateTime; $next = clone $now; $next->modify('+1 day') // 1 day ->modify('+14 hours') // 1 day 14 hours ->modify('-3 minutes') // 1 day 13 hours 57 mins ->modify('13 seconds'); // 1 day 13 hours 57 mins 13 seconds $interval = new \RM\DateInterval($now->diff($next)); echo (string) $interval; // P1DT13H57M13S $interval = new \RM\DateInterval($string); echo $interval->format('%dd %hh %im %ss'); // 1d 13h 57m 13s
Alternatively it's possible use only static method RM\DateInterval::parse(DateInterval $interval).
rm/dateinterval 适用场景与选型建议
rm/dateinterval 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.96k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2017 年 10 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 rm/dateinterval 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 rm/dateinterval 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 1.96k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-10-13