示例#1
0
 /**
  * Timezone/Timescale identifier
  * @param type $str
  */
 private function format_e(&$str)
 {
     if (strstr($str, '%e') || strstr($str, '%T')) {
         $t = $this->timescale == TimeScale::UTC() ? $this->timezone : $this->timescale;
         $str = str_replace('%e', $t, $str);
         $str = str_replace('%T', $t, $str);
     }
 }
示例#2
0
 /**
  * @covers Marando\AstroDate\AstroDate::toUT1
  */
 public function testToUT1()
 {
     $tai = AstroDate::jd(2453750.5 + 0.892482639, TimeScale::TAI());
     $ut1 = AstroDate::jd(2453750.5 + 0.8921045614537036, TimeScale::UT1());
     $this->assertEquals($ut1->toJD(), $tai->toUT1()->toJD(), 'TAI -> UT1', 1.0E-5);
     $tt = AstroDate::jd(2453750.5 + 0.892855139, TimeScale::TT());
     $ut1 = AstroDate::jd(2453750.5 + 0.8921045614537036, TimeScale::UT1());
     $this->assertEquals($ut1->toJD(), $tt->toUT1()->toJD(), 'TT -> UT1', 1.0E-5);
     $utc = AstroDate::jd(2453750.5 + 0.892100694, TimeScale::UTC());
     $ut1 = AstroDate::jd(2453750.5 + 0.8921045614537036, TimeScale::UT1());
     $this->assertEquals($ut1->toJD(), $utc->toUT1()->toJD(), 'UTC -> UT1', 1.0E-5);
 }
示例#3
0
 /**
  * Converts this instance to the Coordinated Universal Time scale (UTC), or
  * if a time zone was set then that timezone
  *
  * @return static
  * @throws Exception Occurs if UTC cannot be computed
  */
 public function toUTC()
 {
     if ($this->timescale == TimeScale::UTC()) {
         // Remove the timezone and set to UTC
         $offset = $this->timezone->offset($this->toJD());
         $this->sub(Time::hours($offset));
         $this->timezone = $this->timezone0 ? $this->timezone0 : TimeZone::UTC();
         return $this;
     }
     // TAI -> UTC
     if ($this->timescale == TimeScale::TAI()) {
         $tai1 = $this->jd;
         $tai2 = $this->dayFrac;
         IAU::Taiutc($tai1, $tai2, $utc1, $utc2);
         $this->jd = $utc1;
         $this->dayFrac = $utc2;
         $this->timescale = TimeScale::UTC();
         return $this;
     }
     // TT -> UTC
     if ($this->timescale == TimeScale::TT()) {
         $tt1 = $this->jd;
         $tt2 = $this->dayFrac;
         IAU::Tttai($tt1, $tt2, $tai1, $tai2);
         IAU::Taiutc($tai1, $tai2, $utc1, $utc2);
         $this->jd = $utc1;
         $this->dayFrac = $utc2;
         $this->timescale = TimeScale::UTC();
         return $this;
     }
     // UT1 -> UTC
     if ($this->timescale == TimeScale::UT1()) {
         $ut11 = $this->jd;
         $ut12 = $this->dayFrac;
         $dut1 = IERS::jd($ut11 + $ut12)->dut1();
         IAU::Ut1utc($ut11, $ut12, $dut1, $utc1, $utc2);
         $this->jd = $utc1;
         $this->dayFrac = $utc2;
         $this->timescale = TimeScale::UTC();
         return $this;
     }
     // TDB -> UTC
     if ($this->timescale == TimeScale::TDB()) {
         $tt1 = $this->jd;
         $tt2 = $this->dayFrac;
         $ut = $this->dayFrac;
         $dtr = IAU::Dtdb($tt1, $tt2, $ut, 0, 0, 0);
         $tdb1 = $this->jd;
         $tdb2 = $this->dayFrac;
         IAU::Tdbtt($tdb1, $tdb2, $dtr, $tt1, $tt2);
         IAU::Tttai($tt1, $tt2, $tai1, $tai2);
         IAU::Taiutc($tai1, $tai2, $utc1, $utc2);
         $this->jd = $utc1;
         $this->dayFrac = $utc2;
         $this->timescale = TimeScale::UTC();
         return $this;
     }
     throw new Exception('Error converting to UTC');
 }