danoha/date-range 问题修复 & 功能扩展

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

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

danoha/date-range

最新稳定版本:v1.1.0

Composer 安装命令:

composer require danoha/date-range

包简介

Working with date ranges made easy.

README 文档

README

Working with date ranges made easy.

Installation

Works best with composer. 👌

composer require danoha/date-range

If you do not use composer or its autoloading, require src/DateRange.php and src/DateRangeCollection.php.

Then use \Danoha\DateRange and \Danoha\DateRangeCollection classes directly in your code.

Usage

Working with date range:

$range = new \Danoha\DateRange($from, $to); // any parameter can be NULL
$range
    ->join($thatRange)
    ->intersect([ $from, $to ]) // methods accepting range also accept array
    ->contains($currentDate);

Work with date range collection:

$coll = new \Danoha\DateRangeCollection([
    [ $from, $to ], // two items per range accepted
    [ 'from' => $from, 'to' => $to, ], // accepted too
    
    [ $from, NULL, ], // NULL means indefinite interval
    [ NULL, NULL, ], // and can be used on both sides
]);

$coll
    ->join($thatCollection)
    ->intersect([ $range1, $range2 ]) // methods accepting collection also accept array
    ->contains($someRange);

To get your ranges back:

$coll->getRanges() === [
    new \Danoha\DateRange($from, $to),
    new \Danoha\DateRange($from, NULL),
];

$coll->unwrap() === [
    [ 'from' => $from, 'to' => $to, ], // every range has this exact format
    [ 'from' => $from, 'to' => NULL, ], // regardless of what was passed to constructor
    ...
];

Every method that accepts collection also accepts array of ranges (which can be arrays, too):

$coll->intersect(
    // another collection
    new \Danoha\DateRangeCollection([ ... ])
);

$coll->intersect([
    // inlined collection (same as constructor)
    [ 'from' => $from, 'to' => $to, ]
]);

Note: definite intervals are handled as inclusive on both sides.

Available range methods

Note: all methods returning range return new instance. That means calling $range->join(...) twice on the same range will create two instances and neither of them will contain both joined ranges.

  • getFrom - returns first date in range,
  • getTo - returns last date in range,
  • unwrap - gets range in array format,
  • intersect - finds intersection between current and given range,
  • overlaps - tests if current and given range overlap,
  • join - finds common range between current and given range,
  • isRightAfter - tests if current range is right after given range,
  • isRightBefore - tests if current range is right before given range,
  • subtract - returns collection of differences between current and given range,
  • includes - tests if range includes given date or range,
  • includesDate - tests if range includes given date,
  • includesRange - tests if range includes given range,
  • equals - tests if current range is equal to given range.

Available collection methods

Note: all methods returning collection return new instance. That means calling $coll->add(...) twice on the same collection will create two instances and neither of them will contain both added ranges.

  • getRanges - gets ranges in current collection,
  • unwrap - gets underlying date ranges in array format,
  • add - adds given ranges to collection,
  • includes - tests if collection includes given date or range,
  • join - adds given ranges to current collection and joins ranges in current collection if possible,
  • intersect - calculates all intersections with given ranges,
  • subtract - subtracts given ranges from current collection.

danoha/date-range 适用场景与选型建议

danoha/date-range 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 16.55k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2017 年 06 月 07 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 danoha/date-range 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-06-07