srtfisher / time-iterator
This package is abandoned and no longer maintained.
No replacement package was suggested.
0.0.2
2015-08-13 05:24 UTC
Requires
- php: >=5.5.9
- nesbot/carbon: ~1.20
Requires (Dev)
- phpunit/phpunit: ~3.7.0
This package is auto-updated.
Last update: 2021-03-24 22:53:43 UTC
README
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.