sunfoxcz/date-utils

Library for easier working with date intervals.

v3.0.0-alpha1 2021-03-15 19:06 UTC

This package is auto-updated.

Last update: 2021-04-15 19:41:45 UTC


README

68747470733a2f2f62616467656e2e6e65742f6769746875622f636865636b732f73756e666f78637a2f646174652d7574696c732f6d61737465723f63616368653d333030 68747470733a2f2f62616467656e2e6e65742f636f766572616c6c732f632f6769746875622f73756e666f78637a2f646174652d7574696c733f63616368653d333030 68747470733a2f2f62616467656e2e6e65742f6769746875622f6c6963656e73652f73756e666f78637a2f646174652d7574696c73

68747470733a2f2f62616467656e2e6e65742f7061636b61676973742f646d2f73756e666f78637a2f646174652d7574696c73 68747470733a2f2f62616467656e2e6e65742f7061636b61676973742f762f73756e666f78637a2f646174652d7574696c73 68747470733a2f2f62616467656e2e6e65742f7061636b61676973742f7068702f73756e666f78637a2f646174652d7574696c73

Library for easier working with date intervals.

Installation

composer require sunfoxcz/date-utils

Usage

DateIntervalFactory

<?php declare(strict_types=1);

use Sunfox\DateUtils\DateTime;
use Sunfox\DateUtils\DateIntervalFactory;

$start = new DateTime('2015-01-01');
$end = new DateTime('2015-12-31');

$months = DateIntervalFactory::create($start, $end, DateIntervalFactory::MONTH, 1, [
	'incomes' => [],
	'expenses' => [],
]);

foreach ($months as $k => $month) {
	echo "{$k}: " . $month->date->format('Y-m-d') . PHP_EOL;
}

SpentTime

<?php declare(strict_types=1);

use Sunfox\DateUtils\SpentTime;

$spentTime = new SpentTime('1h30m');

echo (string) $spentTime; // 01:30:00
echo $spentTime->getTotalHours(); // 1,5
echo $spentTime->getTotalMinutes(); // 90
echo $spentTime->getTotalSeconds(); // 5400

For more usages Look into tests directory.