示例#1
0
 public function testInstanceFromDateTimeKeepsMicros()
 {
     $micro = 254687;
     $datetime = \DateTime::createFromFormat('Y-m-d H:i:s.u', '2014-02-01 03:45:27.' . $micro);
     $date = Date::instance($datetime);
     $this->assertSame($micro, $date->getMicro());
 }
示例#2
0
文件: Date.php 项目: hmlb/date
 /**
  * Get the difference by the given interval using a filter closure.
  *
  * @param Interval  $ci       An interval to traverse by
  * @param Closure   $callback
  * @param Date|null $dt
  * @param bool      $abs      Get the absolute of the difference
  *
  * @return int
  */
 public function diffFiltered(Interval $ci, Closure $callback, Date $dt = null, $abs = true)
 {
     $start = $this;
     $end = $dt ?: static::now($this->getTimezone());
     $inverse = false;
     if ($end < $start) {
         $start = $end;
         $end = $this;
         $inverse = true;
     }
     $period = new DatePeriod($start, $ci, $end);
     $vals = array_filter(iterator_to_array($period), function (DateTimeInterface $date) use($callback) {
         return call_user_func($callback, Date::instance($date));
     });
     $diff = count($vals);
     return $inverse && !$abs ? -$diff : $diff;
 }