/** * {@inheritdoc} */ public static function fromInternal($stamp, $format = null) { if (!in_array(strtolower($format), ['jd', 'gjd', 'geo', 'geo-centric', 'rjd', 'reduced', 'mjd', 'modified', 'tjd', 'truncated', 'djd', 'dublin', 'j1900', 'j2000', 'lilian', 'rata-die', 'mars-sol'])) { $format = 'gjd'; } $jdc = BC::add(BC::div(Calends::fromInternalToUnix($stamp), 86400, 18), 2440587.5, 18); if (in_array(strtolower($format), ['jd', 'gjd', 'geo', 'geo-centric'])) { $output = $jdc; } elseif (in_array(strtolower($format), ['rjd', 'reduced'])) { $output = BC::sub($jdc, '2400000', 18); } elseif (in_array(strtolower($format), ['mjd', 'modified'])) { $output = BC::sub($jdc, '2400000.5', 18); } elseif (in_array(strtolower($format), ['tjd', 'truncated'])) { $output = BC::intval(BC::sub($jdc, '2440000.5', 18), 0); } elseif (in_array(strtolower($format), ['djd', 'dublin', 'j1900'])) { $output = BC::sub($jdc, '2415020', 18); } elseif (in_array(strtolower($format), ['j2000'])) { $output = BC::sub($jdc, '2451545', 18); } elseif (in_array(strtolower($format), ['lilian'])) { $output = BC::intval(BC::sub($jdc, '2299159.5', 18), 0); } elseif (in_array(strtolower($format), ['rata-die'])) { $output = BC::intval(BC::sub($jdc, '1721424.5', 18), 0); } elseif (in_array(strtolower($format), ['mars-sol'])) { $output = BC::div(BC::sub($jdc, '2405522', 18), '1.02749', 18); } return $output; }
/** * {@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'); }
/** * 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'); }
/** * Convert number of seconds to unit => value array * * @param float|string $seconds The number of seconds to convert * @return array */ protected function tsToUnits($seconds) { $unit = $this->units()->where('scale_to', 0)->first(); return $this->addUnits($this->getEpochUnitArray(true), [$unit->internal_name => BC::mul($seconds, $unit->scale_inverse ? BC::div(1, $unit->scale_amount, 18) : $unit->scale_amount, 18)]); }
public function carryOver(array $unitArray) { $myVal = $this->is_auxiliary ? 0 : BC::sub(Arr::get($unitArray, $this->internal_name, $this->uses_zero ? 0 : 1), $this->uses_zero ? 0 : 1, 18); $exprInverse = '({myVal} * {scale}) %% {scale}'; $exprNormal = '({myVal} - ({myVal} %% {scale})) / {scale}'; foreach ($this->scalesToMe()->get() as $unit) { $unitVal = BC::sub(Arr::get($unitArray, $unit->internal_name, $unit->uses_zero ? 0 : 1), $unit->uses_zero ? 0 : 1, 18); $unitAdjustment = 0; $myAdjustment = 0; if ($unit->scale_inverse) { $adjComp = 1; $unitExpr = $exprInverse; $myExpr = '{adjust} / {scale}'; } else { $adjComp = $myVal; $unitExpr = $exprNormal; $myExpr = '{adjust} * {scale}'; } if (!is_null($unit->scale_amount)) { $unitAdjustment = BC::parse($unitExpr, ['myVal' => $myVal, 'scale' => $unit->scale_amount], 18); $myAdjustment = BC::parse($myExpr, ['adjust' => $unitAdjustment, 'scale' => $unit->scale_amount], 18); } else { $lengths = $unit->lengths()->get(); $lCount = $lengths->count(); $lSum = $lengths->sum('scale_amount'); if ($lCount > 0) { $unitAdjustment = BC::add($unitAdjustment, BC::parse("({$unitExpr}) * {$lCount}", ['myVal' => $myVal, 'scale' => $lSum], 18), 18); $myAdjustment = BC::add($myAdjustment, BC::parse($myExpr, ['adjust' => BC::div($unitAdjustment, $lCount, 18), 'scale' => $lSum], 18), 18); for ($lNum = 0; BC::comp($adjComp, $myAdjustment) > 0 && BC::comp($myVal, $lengths[$lNum]->scale_amount) >= 0; $lNum = BC::parse("({$lNum} + 1) % {$lCount}", null, 0)) { $unitAdjustment = BC::add($unitAdjustment, 1, 18); $myAdjustment = BC::add($myAdjustment, $lengths[$lNum]->scale_amount, 18); } if (BC::comp($adjComp, $myAdjustment) < 0) { $unitAdjustment = BC::sub($unitAdjustment, 1, 18); $myAdjustment = BC::sub($myAdjustment, $lengths[BC::parse("({$lNum} - 1 + {$lCount}) % {$lCount}", null, 0)]->scale_amount, 18); } } } $unitArray[$unit->internal_name] = BC::add(BC::add($unitVal, $unitAdjustment, 18), $unit->uses_zero ? 0 : 1, 18); if (!$unit->is_auxiliary) { $unitArray[$this->internal_name] = $myVal = BC::add(BC::sub($myVal, $myAdjustment, 18), $this->uses_zero ? 0 : 1, 18); } $unitArray = $unit->carryOver($unitArray); } return $unitArray; }