src/Marando/AstroDate/AstroDate.php
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');
    }
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');
    }
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