Skip to content

Commit

Permalink
Merge pull request #91 from WimDeMeester/master
Browse files Browse the repository at this point in the history
Fixes for equation of time
  • Loading branch information
WimDeMeester authored Feb 29, 2024
2 parents e4b57a1 + 1e7a692 commit 86ef446
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
7 changes: 7 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 7 additions & 4 deletions src/deepskylog/AstronomyLibrary/Targets/Sun.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -715,11 +714,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;

Expand All @@ -734,7 +733,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;
}

/**
Expand Down
3 changes: 1 addition & 2 deletions tests/Unit/SunTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -120,7 +119,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()
Expand Down

0 comments on commit 86ef446

Please sign in to comment.