chancegarcia/php-time-elapsed

Library for elapsed time using DateInterval. Figure out if x time has elapsed.

2.0.0 2018-01-29 03:40 UTC

This package is auto-updated.

Last update: 2024-10-05 02:49:18 UTC


README

This library is made to figure out elapsed time. Such as: "has 30 minutes elapsed so I can refresh this authentication token?"

Installation

    composer require chancegarcia/php-time-elapsed

Usage

    <?php
    
    ...
    
    $start = new \DateTime("2017-01-01");
    $end = clone $start;
    $end->modify("+1 hour");
    $diff = $start->diff($end);
    
    $service = new TimeElapsedService($diff);
    
    $service->hasMinutesElapsed(20); // true
    $service->hasTimeElapsed(1, 'minute'); // true
    $service->hasTimeElapsed(20, 'minutes'); // true
    $service->hasMinutesElapsed(90) // false
    $service->hasTimeElapsed(90, 'minutes'); // false