/** * @covers ::offset */ public function testOffset() { $this->assertEquals(['seconds' => BC::add(BC::pow(2, 62), 86400), 'nano' => 0, 'atto' => 0], Hebrew::offset(['seconds' => BC::pow(2, 62), 'nano' => 0, 'atto' => 0], '1 day')); }
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()); }
/** * {@inheritdoc} */ public static function offset($stamp, $offset) { return static::toInternal(BC::add(static::fromInternal($stamp), $offset, 18)); }
/** * {@inheritdoc} */ public static function convert(Calends $cal) { return ['start' => Source::createFromFormat('U.u', BC::add($cal->getDate('unix'), 0, 6)), 'duration' => new DateInterval("PT{$cal->getDuration(0)}S"), 'end' => Source::createFromFormat('U.u', BC::add($cal->getEndDate('unix'), 0, 6))]; }
/** * Convert an internal TAI array to a Unix timestamp * * @internal * * @param string[] $stamp The internal TAI array representation to convert * into a Unix timestamp * @return string|float|integer */ public static function fromInternalToUnix($time) { return BC::add(BC::sub($time['seconds'], BC::pow(2, 62, 18), 0), BC::div(BC::add(BC::div($time['atto'], BC::pow(10, 9, 18), 9), $time['nano'], 9), BC::pow(10, 9, 18), 18), 18); }
/** * {@inheritdoc} */ public static function fromInternal($stamp, $format = null) { $date = Calends::fromInternalToUnix($stamp); return date_create_from_format('n/j/Y', \JDToJulian(BC::add(BC::div($date, 86400, 18), 2440587.5, 0)))->format('D, d M Y') . ' ' . date_create_from_format('U.u', BC::add(0, $date, 6))->format('H:i:s.u P'); }
/** * {@inheritdoc} */ public static function convert(Calends $cal) { $dtClass = class_exists('\\DateTimeImmutable') ? '\\DateTimeImmutable' : '\\DateTime'; return new Source($dtClass::createFromFormat('U.u', BC::add($cal->getDate('unix'), 0, 6)), $dtClass::createFromFormat('U.u', BC::add($cal->getEndDate('unix'), 0, 6))); }
/** * @covers ::offset */ public function testOffset() { $this->assertEquals(['seconds' => BC::add(BC::pow(2, 62), 86400), 'nano' => 0, 'atto' => 0], JulianDayCount::offset(['seconds' => BC::pow(2, 62), 'nano' => 0, 'atto' => 0], 1)); }
/** * Combine two unit => value arrays * * Adds each unit, carrying over values too large for a given unit to the * next largest one. * * @param array $a A unit => value array to add, generally a date * @param array $b A unit => value array to add, generally an offset * @return array */ protected function addUnits(array $a, array $b) { // Combine unit => value arrays $sum = []; foreach ($a as $unitName => $value) { $sum[$unitName] = BC::add($value, isset($b[$unitName]) ? $b[$unitName] : 0, 18); } foreach ($b as $unitName => $value) { if (!isset($sum[$unitName])) { $sum[$unitName] = BC::add($value, 0, 18); } } // Perform carryover $coreUnit = $this->units()->where('scale_to', 0)->first(); $sum = $coreUnit->carryOver($sum); return $sum; }
/** * {@inheritdoc} */ public static function offset($stamp, $offset) { $date = date_create_from_format('U.u', BC::add(Calends::fromInternalToUnix($stamp), 0, 6))->modify($offset); return Calends::toInternalFromUnix($date->getTimestamp()); }
public function getFormatArgs(array $units) { $raw = BC::add(array_key_exists($this->internal_name, $units) ? $units[$this->internal_name] : 0, 0, 0); if (is_null($this->scale_amount)) { if (with($lenObj = $this->lengths()->where('unit_value', $raw))->count() > 0) { $length = $lenObj->first()->scale_amount; } else { $length = 0; } } else { $length = $this->scale_amount; } return ['length' => $length, 'value' => $raw]; }
/** * {@inheritdoc} */ public static function offset($stamp, $offset) { return Calends::toInternalFromUnix(BC::add(Calends::fromInternalToUnix($stamp), BC::add(Calends::fromInternalToUnix(static::toInternal($offset)), 0x4000000000000000, 18), 18)); }
/** * @covers ::gap */ public function testGap() { $test = Calends::create(['start' => -86400, 'end' => 0], 'unix')->gap(Calends::create(['start' => 86400, 'end' => 172800], 'unix')); $this->assertInstanceOf('Danhunsaker\\Calends\\Calends', $test); $this->assertAttributeEquals(['seconds' => BC::pow(2, 62), 'nano' => '0', 'atto' => '0'], 'internalTime', $test); $this->assertAttributeEquals(86400, 'duration', $test); $this->assertAttributeEquals(['seconds' => BC::add(BC::pow(2, 62), 86400), 'nano' => '0', 'atto' => '0'], 'endTime', $test); $this->setExpectedException('Danhunsaker\\Calends\\InvalidCompositeRangeException', "The ranges given overlap - they have no gap."); $test->gap(Calends::create(43200, 'unix')); }
/** * @covers ::offset */ public function testOffset() { $this->assertEquals(['seconds' => BC::add(BC::pow(2, 62), 86400), 'nano' => 0, 'atto' => 0], Calendar::find(1)->offset(['seconds' => BC::pow(2, 62), 'nano' => 0, 'atto' => 0], '1 day')); }