philippwitzmann/date-time-handler

Date and Time Framework

1.2 2019-12-31 09:55 UTC

This package is auto-updated.

Last update: 2025-03-29 00:59:15 UTC


README

This library aims to provide basic functionality to work with (testable) Date, Time and DateTime Objects.

Installation

composer require philippwitzmann/date-time-handler

Usage

Create an instance

With set time

$year  = 2000;
$month = 12;
$day   = 30;

$hours    = 20;
$minutes  = 58;
$seconds  = 13;

$timeZone = new DateTimeZone('Europe/Berlin');

$dateTimeHandler = new DateTimeHandler(
    $year, $month, $day, $hours, $minutes, $seconds, $timeZone
);

With current time

$dateTimeHandler = new DateTimeHandler();

Diff two DateTimes

$dateTimeHandler = new DateTimeHandler(
            $year, $month, $day, $hours, $minutes, $seconds, $timeZone
        );

$date                  = new Date($year + 1, $month, $day);
$time                  = new Time($hours, $minutes, $seconds);
$dateTimeToDiffAgainst = new DateTime(
    $date, $time, $timeZone
);

$dateInverval = $dateTimeHandler->diff($dateTimeToDiffAgainst);

Set Test Time

$dateTimeHandler = new DateTimeHandler();
$dateTimeHandler->setTestNow(); //freezes time

$dateTimeHandler->getTime(); // returns the Time, setTestNow() was called at.

Running tests

php vendor/bin/phpunit tests/ --configuration=config/phpunit.xml