예제 #1
0
 public static function createFromDateRange($db, $from, $to)
 {
     $resultSet = new ResultSet($db);
     // add all the shards to the array if they exist
     $interval = DateInterval::createFromDateString('1 day');
     $period = new DatePeriod($from, $interval, $to);
     $shardDates = [];
     foreach ($period as $dt) {
         $shard = new Shard($db, $dt->format('Y'), $dt->format('m'), $dt->format('d'));
         if ($shard->exists()) {
             // Only set the query range if it overlaps this shard
             if ($from->format('Y-m-d') == $dt->format('Y-m-d') || $to->format('Y-m-d') == $dt->format('Y-m-d')) {
                 $shard->setQueryRange($from, $to);
             }
             $resultSet->_shards[] = $shard;
             $shardDates[] = $dt->format('Y-m-d');
         }
     }
     // The last shard may not have been reached by the iterator, for example if
     // the from timestamp starts at 17:00 and the end timestamp is 10:00
     if (!in_array($to->format('Y-m-d'), $shardDates)) {
         $shard = new Shard($db, $to->format('Y'), $to->format('m'), $to->format('d'));
         if ($shard->exists()) {
             $shard->setQueryRange($from, $to);
             $resultSet->_shards[] = $shard;
         }
     }
     return $resultSet;
 }
예제 #2
0
파일: DB.php 프로젝트: aaronpk/QuartzDB
 public function lastShard()
 {
     $key = file_get_contents($this->lastShardFile());
     if (!array_key_exists($key, $this->_shards)) {
         $date = new DateTime($key, self::UTC());
         $shard = Shard::createFromDate($this, $date);
     } else {
         $shard = $this->_shards[$key];
     }
     return $shard;
 }