jarnstedt/timerange 问题修复 & 功能扩展

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

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

jarnstedt/timerange

Composer 安装命令:

composer require jarnstedt/timerange

包简介

Compare and loop time ranges in PHP.

README 文档

README

Compare and loop time ranges in PHP.

Install

For manual install copy timerange.php to your project.

Install with Composer:

composer.phar require jarnstedt/timerange

Examples

Creating a TimeRange object

use TimeRange;

// Create a new TimeRange
$timeRange1 = new TimeRange('2013-03-31 00:00:00', '2013-04-01 01:09:00');

// You can also use PHP DateTime objects
$start = new DateTime('2000-01-01');
$end = new DateTime('2000-01-05');
$timeRange2 = new TimeRange($start, $end);

Looping TimeRange

TimeRange supports looping minutes, hours, days and months.

// Echo all days in time range
foreach ($timeRange1->getDays() as $datetime) {
  echo $datetime->format('Y-m-d')."<br>";
}

// Echo every other day in time range backwards
foreach ($timeRange1->getDays(2, TimeRange::BACKWARD) as $datetime) {
  echo $datetime->format('Y-m-d')."<br>";
}

// Echo all minutes
foreach ($timeRange1->getMinutes() as $datetime) {
  echo $datetime->format('Y-m-d H:i')."<br>";
}

Check if two TimeRanges overlap

$timeRange1 = new TimeRange('2013-03-31 00:00', '2013-04-01 01:09');
$timeRange2 = new TimeRange('2013-01-01 12:30', '2013-01-05 14:00');

if ($timeRange1->overlaps($timeRange2)) {
  echo "Ranges overlap";
}

// Check if date overlaps the TimeRange
if ($timeRange1->overlaps("2013-04-01", TimeRange::DAY)) {
  ...
}

Changing start or end of the range

$timeRange = new TimeRange('2013-03-31 00:00', '2013-04-01 01:09');
$timeRange->setStart('2013-02-28');
$timeRange->setEnd('2013-03-03');

Running unit tests

Download phpunit from http://phpunit.de/ and in project directory run:

php phpunit.phar

统计信息

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

GitHub 信息

  • Stars: 4
  • Watchers: 3
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-05-25

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固