mpd/type-dateinterval
Composer 安装命令:
composer require mpd/type-dateinterval
包简介
Extended DateInterval class
README 文档
README
Extension and drop-in replacement of DateInterval class adding ISO 8601 compatibility and comparators
Installation
composer require mpd/type-dateinterval
Usage
require_once 'vendor/autoload.php'; use mpd\Type\DateInterval\DateInterval; $i = new DateInterval("P2Y3M1DT8H4M3S"); echo($i->toDuration() . "\n"); //"P2Y3M1DT8H4M3S" // see https://www.php.net/manual/en/dateinterval.createfromdatestring.php $i = DateInterval::createFromDateString("+2 days"); echo($i->toDuration() . "\n"); //"P2D" // see https://www.php.net/manual/en/dateinterval.format.php echo($i->format("%d days") . "\n"); //"2 days" $b = new DateInterval("PT48H"); $c = new DateInterval("P2D"); echo($b->isExactlyEqual($i)); // false echo($c->isExactlyEqual($i)); // true $date = new DateTime("1970-01-01 00:01:00"); echo($b->cmpRelative($c, $date)); // 0 (equal) $i = new DateInterval("P2DT1S"); echo($c->cmpRelative($i, $date)); // -1 (c < i) echo($i->cmpRelative($c, $date)); // 1 (i > c) $date->add($i); echo($date->format("Y-m-d H:i:s")); // 1970-01-03 00:01:01
class DateInterval { /* Properties */ public int $y; public int $m; public int $d; public int $h; public int $i; public int $s; public float $f; public int $invert; public mixed $days; public bool $from_string; public string $date_string; /* Methods */ public __construct(string $duration) public toDuration(): string public format(string $format): string public cmpRelative(\DateInterval $b, ?DateTimeInterface $baseDate = null): int public isExactlyEqual(\DateInterval $b): bool public static convertToDurationString(\DateInterval $i): string public static createFromDateString(string $datetime): DateInterval|false public static compareRelativeToDate(\DateInterval $a, \DateInterval $b, ?DateTimeInterface $base=null): int public static areExactlyEqual(\DateInterval $a, \DateInterval $b): bool }
Notes
This class is based on php's native DateInterval class, can be used as drop in replacement. but also inherits some recommendations/limitations namely "properties should be considered read only".
isExactlyEqual / areExactlyEqual
Compare intervals by components. 24H != 1D, 24H == 24H, 1D == 1D
cmpRelative / compareRelativeToDate
Intervals cant be easily compared. For reasons like
1Y == 365,366D; 1M == 28,29,30,31D; leap seconds
But you can compare them exactly from given starting point.
You can either specify your own or use implicit current time
which gives accurate enough comparison for a lot of cases.
But yes, in some cases this still might not be kind of comparison you need.
mpd/type-dateinterval 适用场景与选型建议
mpd/type-dateinterval 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 12 月 30 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「iso8601」 「iso 8601」 「duration」 「dateinteval」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 mpd/type-dateinterval 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mpd/type-dateinterval 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 mpd/type-dateinterval 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Classes for manipulate dates and intervals with microseconds precision
laravel iso8601 date validation package
A PHP library providing ISO 639-1 data.
Parse date and time according to the subset of ISO 8601 date/time format used in Vcard [ISO 6350].
VEGAS, the opensource framework for PHP
A database with ISO country information in all configured translations
统计信息
- 总下载量: 4
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 26
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: LGPL-3.0-only
- 更新时间: 2024-12-30