public function testConstruct() { $d = Distance::m(10); $t = Time::sec(1); $v = new Velocity($d, $t); $this->assertEquals(10, $v->ms, 'm/s'); $this->assertEquals(10, $v->dist->m, 'dist'); $this->assertEquals(1, $v->time->sec, 'time'); }
/** * Calculates the nutation in Right Ascension (equation of the equinoxes) for * a given date * * @param AstroDate $date Date to calculate * @return Time Nutation in Right Ascension as time */ public static function inRA(AstroDate $date) { // Copy time as UTC $utc = $date->copy()->toUTC(); // Get the nutations and true obliquity of the date $n = static::find($utc); $ε = static::trueObliquity($utc); // Calculate the nutation in right ascension as seconds of time $nRA = rad2deg($n->long->rad * cos($ε->rad) / 15) * Time::SEC_IN_HOUR; return Time::sec($nRA)->round(4); }
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); }
/** * @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'); } }
/** * Calculates the time required to travel the provided distance at the * velocity of this instance. * * @param Distance $dist * * @return Time */ public function time(Distance $dist) { return Time::sec($dist->m / $this->dist->m * $this->time->sec); }
public function test() { return; // Converts to J2000.0 echo "\n" . AstroDate::parse('2000-Jan-1 12:00:00 TT')->toEpoch(); // Isn't J2000.0 so represented as date echo "\n" . ($e = AstroDate::parse('2000-Jan-1 14:00:00 TT')->toEpoch()); echo "\n\n" . AstroDate::now()->toEpoch(); $d = AstroDate::now()->setTimezone('est'); echo "\n\n" . $d->sinceMidnight(); echo "\n\n"; return; echo "\n" . ($d = AstroDate::now()->setTimezone(TimeZone::UT(-7))); echo "\n" . TimeScale::TT()->abr; echo "\n" . TimeScale::TT()->name; echo "\n" . Epoch::J2000(); echo "\n" . Epoch::J1900(); echo "\n" . Epoch::B1950(); echo "\n" . Epoch::B1900(); echo "\n" . Epoch::B(1954.4423); echo "\n" . Epoch::jd(2455200.5); echo "\n\n" . Epoch::J2000()->toDate(); echo "\n" . Epoch::J1900()->toDate(); echo "\n" . Epoch::B1950()->toDate(); echo "\n" . Epoch::B1900()->toDate(); echo "\n" . Epoch::B(1954.4423)->toDate(); echo "\n\n" . AstroDate::now(); echo "\n" . ($d = AstroDate::now()->setTimezone(TimeZone::parse('EST'))); echo "\n" . $d->toTDB(); echo "\n" . $d->toUTC(); echo "\n" . ($d = AstroDate::now()->setTimezone('MST')); echo "\n" . ($d = AstroDate::now()->setTimezone('PST')); return; echo "\n" . AstroDate::parse('2015-Dec-10 6:00'); echo "\n" . AstroDate::parse('2015-Dec-10 6:00')->setTimezone(TimeZone::parse('EST')); echo "\n" . AstroDate::now(); echo "\n" . AstroDate::now()->setTimezone(TimeZone::parse('EST')); echo "\n" . AstroDate::now()->setTimezone(TimeZone::parse('PST')); echo "\n" . AstroDate::now()->setTimezone(TimeZone::UT(6)); echo "\n" . TimeZone::parse('est')->offset; echo "\n" . TimeZone::parse('est')->offset(2451545.5); echo "\n" . TimeZone::parse('est')->offset(2451589.5); return; echo "\n" . TimeZone::UT(-2); echo "\n" . TimeZone::parse('EST'); echo "\n" . AstroDate::now()->setTimezone(TimeZone::EST())->format(AstroDate::FORMAT_GOOGLE); echo "\n" . AstroDate::now()->setTimezone(TimeZone::UT(-10.5))->format(AstroDate::FORMAT_GOOGLE); echo "\n" . AstroDate::now()->setTimezone(TimeZone::UT(-10))->format(AstroDate::FORMAT_GOOGLE); return; $t = timezone_abbreviations_list(); $s = timezone_identifiers_list(); $e = timezone_name_from_abbr('est'); var_dump($t); return; $d = AstroDate::now()->setTimezone(TimeZone::EST()); echo "\n" . $d->format('r Y-M-c h:i:s.u A T'); echo "\n" . $d->sub(Time::days(15))->format(AstroDate::FORMAT_GENERIC); echo "\n" . $d->sidereal('a'); echo "\n" . $d->sidereal('m'); echo "\n" . $d->format(AstroDate::FORMAT_JPL_FRAC); echo "\n" . $d->sidereal('a', Angle::deg(-82.47)); echo "\n" . $d->sidereal('m', Angle::deg(-82.47)); echo "\n" . $d->sinceMidnight(); echo "\n" . $d->untilMidnight(); /** * TODO: * * - Figure out formula for DST start and end * - Figure out formula for Week # of year * * */ return; echo "\n" . $d->format(DateTime::RSS); echo "\n" . $d; echo "\n" . $d->format(AstroDate::FORMAT_GENERIC); echo "\n" . $d->format(DateTime::ISO8601); return; $str = '2016-Nov-14 17:07:07.120'; echo "\n" . ($d = AstroDate::parse($str)); echo "\n" . ($d = AstroDate::parse($str)->setTimezone(TimeZone::EST())); echo "\n" . $d->format('Z T P O e u s i h H G g a A y Y n M m F W z D Y-m-d j'); $str = '2016-Nov-14 17:07:07.120 TAI'; echo "\n" . ($d = AstroDate::parse($str)); echo "\n" . $d->format('O e u s i h H G g a A y Y n M m F W z D Y-m-d j'); $str = '2015-Nov-1 17:07:07.120 UTC'; $d = AstroDate::parse($str); echo "\n" . $d->format('z w S N l L D Y-m-d j'); return; echo "\n\n" . ($str = '2015-Nov-16 17:07:07.120 TT'); echo "\n" . AstroDate::parse($str); echo "\n\n" . ($str = '-1950-1-16 17:07:07 UTC'); echo "\n" . ($d = AstroDate::parse($str)); echo "\n" . $d->format('Y-m-d'); return; echo "\n" . ($d = AstroDate::now()); echo "\n" . $d->toUT1(); echo "\n" . $d->toTAI(); echo "\n\n" . ($d = AstroDate::now(TimeZone::EST())); echo "\n" . $d->toUT1(); echo "\n" . $d->toTAI(); return; $d = new AstroDate(2017, 11, 15, 7, 0, 0); echo "\n" . $d; echo "\n" . $d->setTimezone(TimeZone::EST()); //var_dump($d); $d = new AstroDate(2017, 6, 15, 7, 0, 0); echo "\n\n" . $d; echo "\n" . $d->setTimezone(TimeZone::EST()); //var_dump($d); $d = new AstroDate(2017, 11, 15, 7, 0, 0); echo "\n\n" . $d; echo "\n" . $d->setTimezone(TimeZone::EST()); //var_dump($d); $d = new AstroDate(2017, 6, 15, 6, 0, 0); echo "\n\n" . $d; echo "\n" . $d->setTimezone(TimeZone::EST()); //var_dump($d); return; $d = new AstroDate(2017, 11, 15, 0, 0, 0); echo "\n" . $d; echo "\n" . $d->jd(); echo "\n" . $d->jd(12); echo "\n" . $d->toTT(); echo "\n" . $d->toJD(); echo "\n" . $d->jd(12); echo "\n"; $d = new AstroDate(2015, 11, 15, 20, 23, 18, TimeZone::EST(), TimeScale::TT()); echo "\n" . $d; echo "\n" . $d->setTimezone(TimeZone::UTC()); echo "\n" . $d->toUT1(); echo "\n" . $d->setTimezone(TimeZone::EST()); echo "\n" . $d->jd(); echo "\n" . $d->jd(12); echo "\n" . $d->mjd(); echo "\n" . $d->mjd(12); echo "\n" . $d->monthName(); echo "\n" . $d->mjd(); echo "\n\n" . $d->toTAI(); echo "\n" . $d->year; echo "\n" . $d->month; echo "\n" . $d->day; echo "\n" . $d->hour; echo "\n" . $d->min; echo "\n" . $d->sec; echo "\n" . $d->micro; echo "\n" . $d->timezone; echo "\n" . $d->timescale; $d->year = 2020; echo "\n" . $d; $d->month = 12.13432; echo "\n" . $d; $d->sec = 12; echo "\n" . $d; echo "\n" . $d->add(Time::sec(0.5)); echo "\n" . $d->setDateTime(2017, 9, 4, 18, 34, 34.234); var_dump($d->isLeapYear()); echo "\n" . $d->setDateTime(2016, 9, 4, 18, 34, 34.234); var_dump($d->isLeapYear()); echo "\n" . $d->dayName(); $a = new AstroDate(2016, 12, 25, 19, 10, 2); $b = new AstroDate(2015, 12, 25, 19, 10, 2); echo "\n" . $a->diff($b); echo "\n" . ($a = new AstroDate(2016, 12, 31, 19, 10, 2)); echo "\n" . ($b = new AstroDate(2015, 12, 31, 19, 10, 2)); echo "\n" . $a->dayOfYear(); echo "\n" . $b->dayOfYear(); echo "\n\n" . $b; echo "\n" . $b->toTDB(); echo "\n" . $b->setTimezone(TimeZone::UTC()); echo "\n" . $b->toTDB(); echo "\n" . $b->setTimezone(TimeZone::EST()); echo "\n" . $b->toTDB(); echo "\n\n\n"; $d = new AstroDate(2015, 11, 15, 20, 23, 18.454334); echo "\n" . $d; echo "\n" . $d->setTimezone(TimeZone::EST()); echo "\n" . $d->toUTC(); echo "\n" . $d->toTAI(); echo "\n" . $d->setTimezone(TimeZone::EST()); echo "\n" . $d->toTT(); return; $d = new AstroDate(2015, 11, 15, 20, 23, 18.454334); echo "\n" . $d; $d = new AstroDate(2015, 11, 15, 20, 23, 18.454334, TimeZone::EST()); echo "\n" . $d; echo "\n" . $d->setDate(2020, 10, 2); echo "\n" . $d->setTime(23, 59, 1); echo "\n" . $d->setTimezone(TimeZone::UTC()); echo "\n" . $d->setTimezone(TimeZone::EST()); }
/** * Subtracts a Time interval from this instance * * @param Time $t * @return static */ public function sub(Time $t) { return $this->add(Time::sec($t->sec * -1)); }