Time Iterator to request data for specific intervals of time.
PHP
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src/Srtfisher
tests
.gitignore
.travis.yml
README.md
composer.json
phpunit.xml

README.md

Build Status

Time Iterator

Making it easier to pull in data for intervals of time over a period of time. This was built so that it would be easier to build graphs that show changes over time for a specific period.

Authors

Maintained by Sean Fisher.

Installation

Install via Composer

{
    "require": {
        "srtfisher/time-iterator": "0.0.2"
    },
}

Usage

use Srtfisher\TimeIterator;

$iterate = new TimeIterator;

// Set the Start date for five months ago
$iterate->setStart(60*60*24*7*5);

// Set the Interval to go over as 24 hours
$iterate->setInterval(60*60*24);

$iterate->setCallback(function(Carbon $start, Carbon $end, TimeIterator $object) {
    // Perform some logic here
    $object->addResults(array(
        'data' => true,
        // ....
    ));
});

// Run it
$iterate->run();

// Now, you can treat the object as an array
foreach ($iterate as $key => $data) {
    // Do something with the data...
}

Handling of Time

When setting the callback, we pass a $start and an $end arguments. Those arguments are Carbon objects. Carbon is a class built off of PHP's DateTime but with better methods to handle time more efficiently.