techlang/date 问题修复 & 功能扩展

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

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

techlang/date

最新稳定版本:2.0

Composer 安装命令:

composer require techlang/date

包简介

PHP DateTime extension

README 文档

README

Build Status Coverage Status Latest Stable Version Latest Unstable Version Total Downloads License

Introduction

Enhance DateTime objects to add calendar months. What this means is that it will keep the day of the month and only modify month number. If the resulting month does not have that day (for example 31 February) it will use the highest day available for that month.

Examples

  • adding a month 6 times; Jan. 31st scenario
$date = new \TechLang\DateTime('2000-01-31');
$date->add(new \DateInterval('P1M'));
echo $date->format('Y-m-d'); // -> 2000-02-29
$date->add(new \DateInterval('P1M'));
echo $date->format('Y-m-d'); // -> 2000-03-31
$date->add(new \DateInterval('P1M'));
echo $date->format('Y-m-d'); // -> 2000-04-30
$date->add(new \DateInterval('P1M'));
echo $date->format('Y-m-d'); // -> 2000-05-31
$date->add(new \DateInterval('P1M'));
echo $date->format('Y-m-d'); // -> 2000-06-30
$date->add(new \DateInterval('P1M'));
echo $date->format('Y-m-d'); // -> 2000-07-31
// and so on
  • adding a month 6 times; Jan. 30th scenario
$date = new \TechLang\DateTime('2001-01-30');
$date->add(new \DateInterval('P1M'));
echo $date->format('Y-m-d'); // -> 2001-02-28
$date->add(new \DateInterval('P1M'));
echo $date->format('Y-m-d'); // -> 2001-03-30
$date->add(new \DateInterval('P1M'));
echo $date->format('Y-m-d'); // -> 2001-04-30
$date->add(new \DateInterval('P1M'));
echo $date->format('Y-m-d'); // -> 2001-05-30
$date->add(new \DateInterval('P1M'));
echo $date->format('Y-m-d'); // -> 2001-06-30
$date->add(new \DateInterval('P1M'));
echo $date->format('Y-m-d'); // -> 2001-07-30
// and so on
  • adding 2 months
$date = \TechLang\DateTime::createFromFormat('Y-m-d', '2000-12-31');
$date->add(new \DateInterval('P2M'));
echo $date->format('Y-m-d');
// this will output: 2001-02-28
  • add anything lower than month, and you loose the initial date
$date = new \TechLang\DateTime('2000-11-30');
$date->add(new \DateInterval('P1M2D'));
echo $date->format('Y-m-d'); // -> 2001-01-01

// because we added 2 days the date is now 2000-01-01 and the original day of 30 is lost
$date->add(new \DateInterval('P1M'));
echo $date->format('Y-m-d'); // -> 2001-02-01

Future development

  • implement sub method

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-06-12