예제 #1
0
파일: TimeTest.php 프로젝트: marando/units
 public function testSign()
 {
     $this->assertEquals('-', Time::sec(-10)->sign);
     $this->assertEquals('-', Time::min(-10)->sign);
     $this->assertEquals('-', Time::hours(-10)->sign);
     $this->assertEquals('-', Time::days(-10)->sign);
     $this->assertEquals('-', Time::weeks(-10)->sign);
     $this->assertEquals('-', Time::hms(-10, 0, 0, 0)->sign);
     $this->assertEquals('-', Time::hms(0, -10, 0, 0)->sign);
     $this->assertEquals('-', Time::hms(0, 0, -10, 0)->sign);
     $this->assertEquals('-', Time::hms(0, 0, 0, -10)->sign);
     $this->assertEquals('+', Time::hms(10, 0, 0, 0)->sign);
     $this->assertEquals('+', Time::hms(1, -10, 0, 0)->sign);
     $this->assertEquals('+', Time::hms(1, 0, -10, 0)->sign);
     $this->assertEquals('+', Time::hms(1, 0, 0, -10)->sign);
     $this->assertEquals('+', Time::sec(10)->sign);
     $this->assertEquals('+', Time::min(10)->sign);
     $this->assertEquals('+', Time::hours(10)->sign);
     $this->assertEquals('+', Time::days(10)->sign);
     $this->assertEquals('+', Time::weeks(10)->sign);
 }
예제 #2
0
 /**
  * @covers Marando\AstroDate\AstroDate::sub
  */
 public function testSub()
 {
     $tests = [[Time::min(10), 2015, 11, 1, 12, 40, 10], [Time::sec(33), 2015, 11, 1, 12, 49, 37], [Time::days(3), 2015, 10, 29, 12, 50, 10], [Time::days(15), 2015, 10, 17, 12, 50, 10], [Time::days(365), 2014, 11, 1, 12, 50, 10], [Time::hours(13), 2015, 10, 31, 23, 50, 10]];
     foreach ($tests as $t) {
         $time = $t[0];
         $y = $t[1];
         $m = $t[2];
         $d = $t[3];
         $h = $t[4];
         $i = $t[5];
         $s = $t[6];
         $dt0 = new AstroDate(2015, 11, 1, 12, 50, 10);
         $dt = $dt0->copy()->sub($time);
         $this->assertEquals($y, $dt->year, $t[0] . ' y');
         $this->assertEquals($m, $dt->month, $t[0] . ' m');
         $this->assertEquals($d, $dt->day, $t[0] . ' d');
         $this->assertEquals($h, $dt->hour, $t[0] . ' h');
         $this->assertEquals($i, $dt->min, $t[0] . ' i');
         $this->assertEquals($s, $dt->sec, $t[0] . ' s');
     }
 }
예제 #3
0
 public function test()
 {
     return;
     $frame = Frame::ICRF();
     $epoch = Epoch::J(2000);
     echo $epoch->toDate()->toTDB();
     echo "\n";
     echo "\n";
     exit;
     $ra = \Marando\Units\Time::hms(11, 16, 46.6);
     $dec = \Marando\Units\Angle::dms(5, 45, 32.5);
     $dist = Distance::au(5.8);
     echo "\n" . ($eq = new Equat($frame, $epoch, $ra, $dec, $dist));
     echo "\n" . ($eq = (new Equat($frame, $epoch, $ra, $dec, $dist))->apparent());
     echo "\n";
     return;
     $frame = Frame::ICRF();
     $epoch = AstroDate::jd(2457335.472615741)->toEpoch();
     $ra = \Marando\Units\Time::hms(11, 16, 46.6);
     $dec = \Marando\Units\Angle::dms(5, 45, 32.5);
     $dist = Distance::au(5.8);
     echo "\n" . ($eq = new Equat($frame, $epoch, $ra, $dec, $dist));
     echo "\n" . ($eq = (new Equat($frame, $epoch, $ra, $dec, $dist))->apparent());
     $eq = new Equat($frame, $epoch, $ra, $dec, $dist);
     $eq->topo = Geo::deg(27, -82);
     echo "\n" . $eq->toHoriz();
     echo "\n" . $eq->apparent();
     echo "\n" . ($h = $eq->toHoriz());
     echo "\n" . $h->az->deg . "\t" . $h->alt->deg;
     echo "\n" . $eq->apparent(\Marando\Units\Pressure::mbar(100), \Marando\Units\Temperature::F(90), 0.85);
     echo "\n" . $eq->toHoriz();
     return;
     $ra = \Marando\Units\Time::hours(14.424354);
     $dec = \Marando\Units\Angle::deg(33.54366);
     $dist = Distance::au(1.5);
     $geo = Geo::deg(27, -82);
     $e = new Equat(Frame::ICRF(), Epoch::jd(2455586), $ra, $dec, $dist);
     $e->topo = $geo;
     echo "\n\n" . $e;
     echo "\n" . $e->apparent();
     $e = new Equat(Frame::ICRF(), Epoch::jd(2455586), $ra, $dec, $dist);
     $e->topo = $geo;
     echo "\n" . $e->apparent();
     $e = new Equat(Frame::ICRF(), Epoch::jd(2455586), $ra, $dec, $dist);
     $e->topo = $geo;
     echo "\n" . $e->toHoriz();
     return;
     $e = new Equat(Frame::ICRF(), Epoch::jd(2455586), $ra, $dec, $dist);
     echo "\n\n" . $e;
     echo "\n" . $e->apparent($geo);
     echo "\n" . $e->apparent()->toHoriz($geo);
     $e = new Equat(Frame::ICRF(), Epoch::jd(2455586), $ra, $dec, $dist);
     echo "\n\n" . $e;
     echo "\n" . $e->apparent();
     echo "\n" . $e->apparent()->toHoriz();
     $e = new Equat(Frame::ICRF(), Epoch::jd(2451586), $ra, $dec, $dist);
     $e->topo = $geo;
     echo "\n\n" . $e;
     echo "\n" . $e->apparent();
     echo "\n" . $e->apparent()->toHoriz();
     return;
     // Position of Mercury
     $x = Distance::au(+1.18052679326447);
     $y = Distance::au(-0.3650485652522116);
     $z = Distance::au(-0.2123422968928603);
     // Velocity of Mercury
     $vx = Velocity::aud(0.02052320553396918);
     $vy = Velocity::aud(0.02828864020900079);
     $vz = Velocity::aud(0.01145246106968459);
     // Frame & epoch
     $frame = Frame::ICRF();
     $epoch = AstroDate::parse('2015-Mar-20')->toEpoch();
     $c = new Cartesian($frame, $epoch, $x, $y, $z, $vx, $vy, $vz);
     echo "\n\n";
     echo $c;
     echo "\n\n";
     echo $c->setUnit('km km/d');
     echo "\n\n";
     echo $c->setUnit('km km/s');
     echo "\n\n";
     echo $c->toEquat();
     echo "\n\n";
     echo $c->toEquat()->apparent();
     echo "\n\n";
     echo $c->toEquat()->apparent(Geo::deg(27, 278));
     echo "\n\n";
     echo $c->toEquat()->toHoriz(Geo::deg(27, 278));
     echo "\n\n";
 }
예제 #4
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');
 }
예제 #5
0
 public function testSetTime()
 {
     $v = Velocity::kms(6);
     $v->time = Time::hours(1);
     $this->assertEquals(6, $v->kmh);
 }
예제 #6
0
파일: AngleTest.php 프로젝트: marando/units
 public function testTime()
 {
     $angle = Angle::time(Time::hours(12));
     $this->assertEquals(180, $angle->deg);
 }