From 3f5af400c75c24db7e652c13659602cec0492155 Mon Sep 17 00:00:00 2001 From: Wim De Meester Date: Thu, 29 Feb 2024 16:12:41 +0100 Subject: [PATCH 1/2] Equation of time fixes. --- changelog.md | 7 +++++++ src/deepskylog/AstronomyLibrary/Targets/Sun.php | 10 +++++++--- tests/Unit/SunTest.php | 2 +- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/changelog.md b/changelog.md index 58b5082..7b14374 100644 --- a/changelog.md +++ b/changelog.md @@ -2,6 +2,13 @@ All notable changes to `laravel-astronomy-library` will be documented in this file. +## Version 6.2 + +Changed: + +- Fix equation of time for March 21 and 22. +- Return equation of time as float and not as CarbonInterval (which fails for negative values). + ## Version 6.1.2 Changed: diff --git a/src/deepskylog/AstronomyLibrary/Targets/Sun.php b/src/deepskylog/AstronomyLibrary/Targets/Sun.php index 88283f8..79d48ce 100644 --- a/src/deepskylog/AstronomyLibrary/Targets/Sun.php +++ b/src/deepskylog/AstronomyLibrary/Targets/Sun.php @@ -715,11 +715,11 @@ public function calculateGeometricCoordinatesJ2000(Carbon $date): RectangularCoo * Calculates the equation of time of the sun for a given date. * * @param Carbon $date The date - * @return CarbonInterval The equation of time + * @return float The equation of time in minutes * * See chapter 28 of Astronomical Algorithms */ - public function calculateEquationOfTime(Carbon $date): CarbonInterval + public function calculateEquationOfTime(Carbon $date): float { $tau = (Time::getJd($date) - 2451545.0) / 365250.0; @@ -734,7 +734,11 @@ public function calculateEquationOfTime(Carbon $date): CarbonInterval $E = $L0->getCoordinate() - 0.0057183 - $ra + $nutation[0] / 3600.0 * cos(deg2rad($nutation[3])); - return CarbonInterval::make($E * 4 .'m'); + if ($E > 180) { + $E = $E - 360; + } + + return $E * 4; } /** diff --git a/tests/Unit/SunTest.php b/tests/Unit/SunTest.php index f6d30cb..83f50db 100644 --- a/tests/Unit/SunTest.php +++ b/tests/Unit/SunTest.php @@ -120,7 +120,7 @@ public function testEquationOfTime() $equationOfTime = $sun->calculateEquationOfTime($date); - $this->assertEquals(CarbonInterval::create(0, 0, 0, 0, 0, 13, 42, 564279), $equationOfTime); + $this->assertEquals(13.7090, $equationOfTime); } public function testPhysicalEphemeris() From 270d57ae24201f54d943db6f5e0fcb4f0da32216 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Thu, 29 Feb 2024 15:13:46 +0000 Subject: [PATCH 2/2] Apply fixes from StyleCI --- src/deepskylog/AstronomyLibrary/Targets/Sun.php | 1 - tests/Unit/SunTest.php | 1 - 2 files changed, 2 deletions(-) diff --git a/src/deepskylog/AstronomyLibrary/Targets/Sun.php b/src/deepskylog/AstronomyLibrary/Targets/Sun.php index 79d48ce..5b4ce61 100644 --- a/src/deepskylog/AstronomyLibrary/Targets/Sun.php +++ b/src/deepskylog/AstronomyLibrary/Targets/Sun.php @@ -16,7 +16,6 @@ namespace deepskylog\AstronomyLibrary\Targets; use Carbon\Carbon; -use Carbon\CarbonInterval; use deepskylog\AstronomyLibrary\Coordinates\Coordinate; use deepskylog\AstronomyLibrary\Coordinates\EclipticalCoordinates; use deepskylog\AstronomyLibrary\Coordinates\EquatorialCoordinates; diff --git a/tests/Unit/SunTest.php b/tests/Unit/SunTest.php index 83f50db..5b8cda9 100644 --- a/tests/Unit/SunTest.php +++ b/tests/Unit/SunTest.php @@ -16,7 +16,6 @@ namespace Tests\Unit; use Carbon\Carbon; -use Carbon\CarbonInterval; use deepskylog\AstronomyLibrary\Targets\Sun; use deepskylog\AstronomyLibrary\Testing\BaseTestCase; use deepskylog\AstronomyLibrary\Time;