alameda-red/datetime
Composer 安装命令:
composer require alameda-red/datetime
包简介
Alameda DateTime component
关键字:
README 文档
README
This component provides a tool-kit to work with PHPs' Date and Time related objects.
Installation
You can either modify your composer.json with
{
"require" : {
"alameda-red/datetime" : "0.*"
}
}
or run:
$ composer require "alameda-red/datetime=0.*"
Usage
Let's start with a warning right away: working with \DateIntervals is not trivial! There is obviously a certain extend boundary in which you can pretty much do anything. As soon as you leave the box you are on your own and there is actually no tool to help you from that point on. This component won't be able to help you either.
When you base your code on working with the values for seconds, minutes, hours and days you are on the safe-side in most cases when working in a narrow timeframe. If you use DateInterval::shorten($interval, true) be sure you understand what this value will represent. An hourly representation (2nd parameter = true) of a leap-year will yield 366 * 24 = 8784 hours while the year representation (2nd parameter = false default) will yield 365 * 24 = 8760 hours.
Divide a \DateInterval
Ever thought about splitting your \DateInterval('P1D') into two parts so you'd have \DateInterval('PT12H')? You can do that:
<?php $interval = new \DateInterval('P1D'); $split = DateInterval::divide($interval, 2); // \DateInterval('PT12H')
Create a shorter, more readable representation of \DateInterval
No idea what \DateTime('PT86400S) means? Make it more readable:
<?php $interval = new \DateInterval('PT86400S'); $short = DateInterval::shorten($interval); // \DateInterval('P1D') $short = DateInterval::shorten($interval, true); // \DateInterval('P1D') $short = DateInterval::shorten($interval, false); // \DateInterval('PT24H')
String representation of a \DateInterval
If you don't want to store your \DateInterval object in a human readable form it is probably more catchy reading 'PT24H' or 'P1D' in your database over the approach of other developers to store the value in seconds (86400):
<?php $interval = new \DateInterval('PT86400S'); $string = DateInterval::getString($interval); // 'P1D' $string = DateInterval::getString($interval, true); // 'P1D' $string = DateInterval::getString($interval, false); // 'PT24H'
Shorten the string by using larger time units
So \DateInterval('PT1440M') is a day, make it look like one:
<?php $interval = new \DateInterval('PT1440M'); $short = DateInterval::shortenString($interval); // 'P1D' $short = DateInterval::shortenString($interval, true); // 'P1D' $short = DateInterval::shortenString($interval, false); // 'PT24H'
Sum up \DateIntervals
Doing calculations with intervals? Struggle no more!
<?php $base = new \DateInterval('PT0H'); $i1 = new \DateInterval('PT1S'); $i2 = new \DateInterval('PT1M'); $i3 = new \DateInterval('PT1H'); $sum = DateInterval::sum($base, $i1, $i2, $i3); // 'PT1H1M1S' $base = new \DateInterval('PT1H1M1S'); $i1 = new \DateInterval('PT1S'); $i1->invert = true; $i2 = new \DateInterval('PT1M'); $i2->invert = true; $i3 = new \DateInterval('PT1H'); $i3->invert = true; $sum = DateInterval::sum($base, $i1, $i2, $i3); // 'PT0H', $sum->invert -> true
alameda-red/datetime 适用场景与选型建议
alameda-red/datetime 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.8k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2015 年 01 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「dateinterval」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 alameda-red/datetime 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 alameda-red/datetime 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 alameda-red/datetime 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Enhanced DateTime, DateTimeImmutable and DateInterval objects
Adds DateInterval to Doctrine DBAL and ORM
Round of DateInterval
Backported Doctrine DBAL DateIntervalType for use with DBAL <2.6
Providing custom Doctrine's PostgreSQL DBAL types
统计信息
- 总下载量: 1.8k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 22
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-01-06