Created
October 20, 2015 17:28
-
-
Save tamakiii/6f7dc58507e99655a60b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
define('KEY_ID', 0); | |
define('KEY_DATE', 1); | |
/** | |
* @param array $reports | |
* @param string $start | |
* @param string $end | |
* @return array | |
*/ | |
function timeFilterYield(array $reports, $start, $end) | |
{ | |
$start = strtotime($start); | |
$end = strtotime($end); | |
foreach ($reports as $report) { | |
$current = strtotime($report[KEY_DATE]) ; | |
if ($start <= $current && $current < $end) { | |
yield $report; | |
} | |
} | |
} | |
$filepath = $argv[1]; | |
$csv = array_filter(explode(PHP_EOL, file_get_contents($filepath))); | |
$reports = array_map('str_getcsv', $csv); | |
iterator_to_array(timeFilterYield($reports, '2015-01-02', '2015-01-05')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment