2017 © Pedro Peláez
 

library date

PHP DateTime extension

image

techlang/date

PHP DateTime extension

  • Monday, April 23, 2018
  • by techlang
  • Repository
  • 2 Watchers
  • 3 Stars
  • 3,858 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 5 % Grown

The README.md

\TechLang\DateTime

Build Status Coverage Status Latest Stable Version Latest Unstable Version Total Downloads License, (*1)

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., (*2)

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

The Versions

23/04 2018

dev-master

9999999-dev http://github.com/techlang/date

PHP DateTime extension

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

date time datetime

27/06 2014

1.1

1.1.0.0 http://github.com/techlang/date

PHP DateTime extension

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

date time datetime

13/06 2014

1.0

1.0.0.0 http://github.com/techlang/date

PHP DateTime extension

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

date time datetime