定制 org_heigl/dateintervalcomparator 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

org_heigl/dateintervalcomparator

Composer 安装命令:

composer require org_heigl/dateintervalcomparator

包简介

Compare two DateInterval-Objects with one another

README 文档

README

Compare two DateInterval-Objects with one another.

Build Status Code Climate Coverage Status Scrutinizer Code Quality

Total Downloads Latest Stable Version License

Installation

DateIntervalComparator is best installed using composer

composer require org_heigl/dateintervalcomparator

Usage

$comparator = new Org_Heigl\DateIntervalComparator\DateIntervalComparator()
echo $comparator->compare(new Dateinterval('P1Y'), new DateInterval('P1M'));
// 1

The DateIntervalComparator uses the same return values all comparison-functions in PHP use. When the first value is smaller than the second it returns -1, if the first is greater than the second it returns 1 and when both are equals it returns 0. The method can therefore be used as callback to sort arrays.

This library assumes that the compared intervals are sensible and alike. Comparing 3 months and 4 days against 5 months and 7 days is what this library is made for. It's not been made for comparing 3 months and 4 days against 94 days. Due to the different number of days in a month this comparison will be different depending on the start-date and we do want to compare only the Intervals and not the resulting end-dates!

As long as the values do not exceed their moduli (e.g. a value of 13 for month or 25 for the hour) you are on the safe side.

You can even enforce this safe side by setting php $comparator->safe(true). That will then throw an exception when one of the values for month, day, hour, minute or second will exceed the values 12, 31, 24, 60 and 60 resp.

Caveat/Limitations

Take care! DateIntervals can be nasty!

Due to their nature DateIntervals do not take Date or Time into account! So DateInterval('P1M') might or might not be the same as DateInterval('P30D')! This Library will compare on a "same entity"-level. So first years are compared, then months, then weeks and so on. When you have an interval that is describing only 55 weeks and compare that to one that is only describing one year, the one year will be considered greater even though 55 weeks are more. So you should only compare comparable intervals!

The same can happen with f.e. new DateInterval('PT36H') and new DateInterval('P1DT12H') You'd think they are the same, but consider DaylightSavingsTime and they suddenly might not be the same! So currently the P1DT12H would be considered the "higher" one.

License

This library is published under the MIT-License. Find a copy in the LICENSE.md-File.

org_heigl/dateintervalcomparator 适用场景与选型建议

org_heigl/dateintervalcomparator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 89.14k 次下载、GitHub Stars 达 8, 最近一次更新时间为 2016 年 10 月 11 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 org_heigl/dateintervalcomparator 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 8
  • Watchers: 1
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-10-11