public function testInstanceFromDateTimeKeepsMicros()
 {
     $micro = 254687;
     $datetime = \DateTime::createFromFormat('Y-m-d H:i:s.u', '2014-02-01 03:45:27.' . $micro);
     $IntlCarbon = IntlCarbon::instance($datetime);
     $this->assertSame($micro, $IntlCarbon->micro);
 }
Example #2
0
 /**
  * Get the difference by the given interval using a filter closure
  *
  * @param CarbonInterval $ci An interval to traverse by
  * @param Closure $callback
  * @param Carbon $dt
  * @param boolean $abs Get the absolute of the difference
  *
  * @return int
  */
 public function diffFiltered(CarbonInterval $ci, Closure $callback, IntlCarbon $dt = null, $abs = true)
 {
     $start = $this;
     $end = $dt === null ? static::now($this->tz) : $dt;
     $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 (DateTime $date) use($callback) {
         return call_user_func($callback, IntlCarbon::instance($date));
     });
     $diff = count($vals);
     return $inverse && !$abs ? -$diff : $diff;
 }
Example #3
0
 /**
  * @param DateTime $datetime
  * @return IntlCalendar
  */
 protected function getCalendarFromDateTime($datetime)
 {
     $calendar = $this->getCalendarObject();
     //        $c = IntlCarbon::createFromTimestamp($datetime->format('U'),$datetime->getTimezone());
     //        $c->setCalendar($calendar->getType());
     $c = IntlCarbon::instance($datetime);
     //        var_dump($c);
     //        var_dump($datetime);
     //        $calendar->setTime($datetime->format('U'));
     //        $calendar->set($datetime->format('Y'), $datetime->format('n') - 1, $datetime->format('d'),
     //            $datetime->format('G'), $datetime->format('i'), $datetime->format('s'));
     $calendar->set($c->format('Y'), $c->format('n') - 1, $c->format('d'), $c->format('G'), $c->format('i'), $c->format('s'));
     return $calendar;
 }
Example #4
0
 /**
  * @param DateTime $datetime
  * @return IntlCalendar
  */
 protected function getCalendarFromDateTime($datetime)
 {
     $calendar = $this->getCalendarObject();
     $c = IntlCarbon::instance($datetime);
     $calendar->set($c->format('Y'), $c->format('n') - 1, $c->format('d'), $c->format('G'), $c->format('i'), $c->format('s'));
     return $calendar;
 }