shrikeh/datetime 问题修复 & 功能扩展

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

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

shrikeh/datetime

最新稳定版本:0.1.1

Composer 安装命令:

composer require shrikeh/datetime

包简介

Simple boilerplate library for dateftime periods and ranges

README 文档

README

Boilerplate collections representing DateTime periods and ranges.

Overview

This adds two utility classes for DateTime usage: Period, a class to describe a DateTime "window" (such as a calendar meeting), and Range, which describes multiple dates and automatically sorts them, earliest to latest.

Installation

Installation is via composer:

composer require shrikeh/datetime

Usage

Both classes are written to ensure dates are immutable and so use DateTimeImmutable internally.

Range

Represent a range of dates. Given the following dates:

<?php

$date1 = new DateTime('+7 days');
$date2 = new DateTimeImmutable();
$date3 = new DateTime('+5 hours');
$date4 = new DateTimeImmutable('-1 hour');

These can then be sorted simply by:

$range = Range::fromDateTimes(
    $date1,
    $date2,
    $date3,
    $date4,
);

foreach ($range() as $date) {
// Will iterate as $date4, $date2, $date3, $date 1
}

The Range has two helper methods, earliest() and latest() which return the outer bounds of the DateTimes. To create a Period from the Range is straightforward:

$range = Range::fromDateTimes(
    new DateTimeImmutable(),
    new DateTimeImmutable('+2 years'),
    new DateTimeImmutable('+1 month'),
);

$period = $range->period();

In the above example, the Period will begin from now and end in two year's time.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-02-22