Exemple #1
0
 /**
  * {@inheritdoc}
  */
 public static function fromInternal($stamp, $format = null)
 {
     $date = Calends::fromInternalToUnix($stamp);
     list($m, $d, $y) = explode('/', \jdtojewish(BC::add(BC::div($date, 86400, 18), 2440587.5, 0)));
     if (\JewishToJD(6, 1, $y) == \JewishToJD(7, 1, $y)) {
         $m = $m == 6 ? '6L' : ($m == 7 ? '7L' : $m);
     }
     return "{$d} " . static::$months[str_pad($m, 2, '0', STR_PAD_LEFT)] . " {$y} " . date_create_from_format('U.u', BC::add(BC::mod($date, 86400, 18), 0, 6))->format('H:i:s.u P');
 }
Exemple #2
0
 public function it_should_modify_dates()
 {
     BC::scale(18);
     $time = microtime(true);
     $start = BC::sub($time, BC::mod($time, 86400), 0);
     $end = BC::add($start, 86400);
     $this->beConstructedWith(['start' => $start, 'end' => $end]);
     $today = $this->getWrappedObject();
     $next24hrs = $today->setDate($time)->setEndDate(BC::add($time, 86400));
     $yesterday = $today->previous('1 day', 'gregorian');
     $subtracted = $this->subtractFromEnd('50', 'unix');
     $subtracted->shouldHaveType('Danhunsaker\\Calends\\Calends');
     $subtracted->getEndDate()->shouldBeLike(BC::sub($this->getWrappedObject()->getEndDate(), 50));
     $duration = $this->setDuration('50', 'unix');
     $duration->shouldHaveType('Danhunsaker\\Calends\\Calends');
     $duration->getEndDate()->shouldBeLike(BC::add($this->getWrappedObject()->getDate(), 50));
     $endDuration = $this->setDurationFromEnd('50', 'unix');
     $endDuration->shouldHaveType('Danhunsaker\\Calends\\Calends');
     $endDuration->getDate()->shouldBeLike(BC::sub($this->getWrappedObject()->getEndDate(), 50));
     $merged = $this->merge($yesterday);
     $merged->shouldHaveType('Danhunsaker\\Calends\\Calends');
     $merged->getDate()->shouldBeLike($yesterday->getDate());
     $merged->getEndDate()->shouldBeLike($this->getWrappedObject()->getEndDate());
     $this->shouldThrow('Danhunsaker\\Calends\\InvalidCompositeRangeException')->duringIntersect($yesterday);
     $intersection = $this->intersect($next24hrs);
     $intersection->shouldHaveType('Danhunsaker\\Calends\\Calends');
     $intersection->getDate()->shouldBeLike($next24hrs->getDate());
     $intersection->getEndDate()->shouldBeLike($this->getWrappedObject()->getEndDate());
     $this->shouldThrow('Danhunsaker\\Calends\\InvalidCompositeRangeException')->duringGap($next24hrs);
     $gap = $this->gap($yesterday);
     $gap->shouldHaveType('Danhunsaker\\Calends\\Calends');
     $gap->getDate()->shouldBeLike($yesterday->getEndDate());
     $gap->getEndDate()->shouldBeLike($this->getWrappedObject()->getDate());
 }
Exemple #3
0
 /**
  * {@inheritdoc}
  */
 public static function toInternal($date, $format = null)
 {
     $greg = new DateTime($date);
     return Calends::toInternalFromUnix(BC::add(BC::mul(BC::sub(\JulianToJD($greg->format('n'), $greg->format('j'), $greg->format('Y')), 2440587, 18), 86400, 18), BC::mod($greg->getTimestamp(), 86400, 18), 18));
 }