<?php

function searchLast($dir, $filter, $delay=600) {
	$iter = new DirectoryIterator($dir);
	$last = NULL;
	$ltime = 0;
	$limit = time()-$delay;

	foreach ($iter as $entry) {
		if ($entry->$filter() && !$entry->isDot()) {
			if ($entry->getMTime() > $ltime && $entry->getMTime() < $limit) {
				$last  = $entry->getFileName();
				$ltime = $entry->getMTime();
			} 
		}
	}
	if ($last) {
		return [ $last, date('Y-m-d', $ltime)];
	}
}

list($last_build_date, $win_last_time) = searchLast("/data/repository/qet/builds/nightly/", 'isDir');
list($latest_filename, $mac_last_time) = searchLast("/data/repository/qet/builds/MAC_OS_X/", 'isFile');

?>
