2017 © Pedro Peláez
 

library datetime

Extends DateTime class for add some comfort.

image

andydune/datetime

Extends DateTime class for add some comfort.

  • Tuesday, June 26, 2018
  • by AndyDune
  • Repository
  • 1 Watchers
  • 0 Stars
  • 85 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 17 Versions
  • 18 % Grown

The README.md

DateTime

Build Status Software License Packagist Version Total Downloads, (*1)

It extends DateTime class to add some comfort., (*2)

Installation

Installation using composer:, (*3)

composer require andydune/datetime

Or if composer was not installed globally:, (*4)

php composer.phar require andydune/datetime

Or edit your composer.json:, (*5)

"require" : {
     "andydune/datetime": "^2"
}

And execute command:, (*6)

php composer.phar update

How to create instance

Constructor without parameters set current time value., (*7)

use AndyDuneTest\DateTime\DateTime;
$dt = new DateTime();
$dt->getTimestamp; // == time()

Constructor with integer parameter is unit seconds., (*8)

use AndyDuneTest\DateTime\DateTime;
$dt = new DateTime(time() + 3600);
$dt->getTimestamp; // == time() + 3600

Constructor with string parameter is the same for function strtotime(), (*9)

use AndyDuneTest\DateTime\DateTime;
$dt = new DateTime('2018-04-11'); // default format is mysql datetime
$dt = new DateTime('11.04.2017', 'd.m.Y'); // own format - use string as for date() function

Constructor with parameter \Datetime type, (*10)

use AndyDuneTest\DateTime\DateTime;
$dt = new DateTime(new \DateTime());

Format datetime

It has method format() to get formated datetiem data as string. Method waits string like date() function., (*11)

use AndyDuneTest\DateTime\DateTime;
$dt = new DateTime();
echo $dt->format('Y-m-d'); // 2107-04-12
echo $dt->format('H:i'); // 10:04

Dates arithmetic.

Each duration period is represented by an integer value followed by a period designator. If the duration contains time elements, that portion of the specification is preceded by the letter T., (*12)

Period Designators: - Y - years, - M - months, - D - days, - W - weeks, - H - hours, - M - minutes, - S - seconds., (*13)

Examples:, (*14)

use AndyDuneTest\DateTime\DateTime;
$dt = new DateTime();
$dt->add('2D'); // two days
$dt->add('T2S'); // two seconds
$dt->add('6YT5M'); // six years and five minutes

The unit types must be entered from the largest scale unit on the left to the smallest scale unit on the right. Use first "-" char for negative periods. OR Relative period., (*15)

Examples:, (*16)

use AndyDuneTest\DateTime\DateTime;
$dt = new DateTime();
$dt->add('+5 weeks'); // 5 weeks to future
$dt->add('12 day'); // 12 days to future
$dt->add('-7 weekdays'); // 7 working daye to past
$dt->add('3 months - 5 days'); // 3 months to future and 5 days to past

Tools

Bring per day statistics to weeks.

If there is no full weekdays number is source data missing days will be added as average., (*17)

Source json:, (*18)

$json = '
   {
    "2018-03-01" : 913,
    "2018-03-03" : 913,
    "2018-03-04" : 913,

    "2018-03-05" : 910,
    "2018-03-07" : 914,
    "2018-03-08" : 915,
    "2018-03-09" : 915,
    "2018-03-11" : 912,

    "2018-03-12" : 869,
    "2018-03-14" : 869,
    "2018-03-16" : 869,
    "2018-03-17" : 864,
}';

use AndyDune\DateTime\Tool\Statistics\BringNumberInDayToNumberInWeek;
$data = json_decode($json, true);

$stat = new BringNumberInDayToNumberInWeek($data);
$weeks = $stat->getWeeksWithCalendarDivision();

Weeks are:, (*19)

 {
    "2018-03-04" : 6391,
    "2018-03-11" : 6393,
    "2018-03-18" : 6075
}

Strategy pattent

There is great instrument to manipulatin with DateTime object without editting existing code in this library., (*20)

Methods

DateTime::setAction(AbstractAction $action) - add action for further execution, (*21)

DateTime::executeAction(...$params) - execute actions with any patrams, (*22)

To know is working day

use AndyDune\DateTime\Action\IsWorkingDay;
use AndyDune\DateTime\DateTime;

$dt = new DateTime('18-04-2018', 'd-m-Y');
$dt->setAction(new IsWorkingDay())->executeAction(); // true

$dt = new DateTime('22-04-2018', 'd-m-Y');
$dt->setAction(new IsWorkingDay())->executeAction(); // false

To know closest working date after pointed days number

There is an action AndyDune\DateTime\Action\PlusWorkingDays for this task., (*23)

use AndyDune\DateTime\Action\PlusWorkingDays;
use AndyDune\DateTime\DateTime;

$dt = new DateTime('28-04-2018', 'd-m-Y');
$action = new PlusWorkingDays();
$action->setNoWorkingDays(['1-05', '30-04']);  // set list of official holidays 
$action->setWorkingDays(['28-04']); // set list of working sundays or saturdays
$dt->setAction($action)->executeAction(1); // to know working date after 1 day

$dt->format('d-m-Y'); // '02-05-2018'
$action->getDaysPlus(); // 4 days

The Versions

26/06 2018

dev-master

9999999-dev https://github.com/AndyDune/DateTime

Extends DateTime class for add some comfort.

  Sources   Download

MIT

The Requires

 

The Development Requires

php datetime

25/06 2018

v2.3.0

2.3.0.0 https://github.com/AndyDune/DateTime

Extends DateTime class for add some comfort.

  Sources   Download

MIT

The Requires

 

The Development Requires

php datetime

08/06 2018

v2.2.2

2.2.2.0 https://github.com/AndyDune/DateTime

Extends DateTime class for add some comfort.

  Sources   Download

MIT

The Requires

 

The Development Requires

php datetime

05/06 2018

v2.2.1

2.2.1.0 https://github.com/AndyDune/DateTime

Extends DateTime class for add some comfort.

  Sources   Download

MIT

The Requires

 

The Development Requires

php datetime

28/05 2018

v2.2.0

2.2.0.0 https://github.com/AndyDune/DateTime

Extends DateTime class for add some comfort.

  Sources   Download

MIT

The Requires

 

The Development Requires

php datetime

28/04 2018

v2.1.3

2.1.3.0 https://github.com/AndyDune/DateTime

Extends DateTime class for add some comfort.

  Sources   Download

MIT

The Requires

 

The Development Requires

php datetime

27/04 2018

v2.1.2

2.1.2.0 https://github.com/AndyDune/DateTime

Extends DateTime class for add some comfort.

  Sources   Download

MIT

The Requires

 

The Development Requires

php datetime

27/04 2018

v2.1.1

2.1.1.0 https://github.com/AndyDune/DateTime

Extends DateTime class for add some comfort.

  Sources   Download

MIT

The Requires

 

The Development Requires

php datetime

23/04 2018

v2.1.0

2.1.0.0 https://github.com/AndyDune/DateTime

Extends DateTime class for add some comfort.

  Sources   Download

MIT

The Requires

 

The Development Requires

php datetime

23/04 2018

v2.0.1

2.0.1.0 https://github.com/AndyDune/DateTime

Extends DateTime class for add some comfort.

  Sources   Download

MIT

The Requires

 

The Development Requires

php datetime

20/04 2018

v2.0.0

2.0.0.0 https://github.com/AndyDune/DateTime

Extends DateTime class for add some comfort.

  Sources   Download

MIT

The Requires

 

The Development Requires

php datetime

19/04 2018

v1.3.0

1.3.0.0 https://github.com/AndyDune/DateTime

Extends DateTime class for add some comfort.

  Sources   Download

MIT

The Requires

 

The Development Requires

php datetime

12/04 2018

v1.2.0

1.2.0.0 https://github.com/AndyDune/DateTime

Extends DateTime class for add some comfort.

  Sources   Download

MIT

The Requires

  • php >=7.1

 

The Development Requires

php datetime

11/04 2018

v1.1.2

1.1.2.0 https://github.com/AndyDune/DateTime

Extends DateTime class for add some comfort.

  Sources   Download

MIT

The Requires

  • php >=7.1

 

The Development Requires

php datetime

09/04 2018

v1.1.1

1.1.1.0 https://github.com/AndyDune/DateTime

Extends DateTime class for add some comfort.

  Sources   Download

MIT

The Requires

  • php >=7.1

 

The Development Requires

php datetime

04/04 2018

v1.1.0

1.1.0.0 https://github.com/AndyDune/DateTime

Extends DateTime class for add some comfort.

  Sources   Download

MIT

The Requires

  • php >=7.1

 

The Development Requires

php datetime

03/04 2018

v1.0.0

1.0.0.0 https://github.com/AndyDune/DateTime

Extends DateTime class for add some comfort.

  Sources   Download

MIT

The Requires

  • php >=7.1

 

The Development Requires

php datetime