Skip to content

Commit

Permalink
Merge pull request #22 from jfcarr-astronomy/sun/equation-time
Browse files Browse the repository at this point in the history
Calculate -> Equation of time
  • Loading branch information
Jim Carr committed Nov 29, 2020
2 parents aedc492 + 7207bdd commit beb9724
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
8 changes: 6 additions & 2 deletions PALib.Tests/PASun.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,13 @@ public void SunriseAndSunset()
[Fact]
public void MorningAndEveningTwilight()
{
var result = _paSun.MorningAndEveningTwilight(7, 9, 1979, false, 0, 0, 52, PATwilightType.Astronomical);
Assert.Equal((3, 17, 20, 37, "OK"), _paSun.MorningAndEveningTwilight(7, 9, 1979, false, 0, 0, 52, PATwilightType.Astronomical));
}

Assert.Equal((3, 17, 20, 37, "OK"), result);
[Fact]
public void EquationOfTime()
{
Assert.Equal((6, 31.52), _paSun.EquationOfTime(27, 7, 2010));
}
}
}
23 changes: 23 additions & 0 deletions PALib/PASun.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,5 +217,28 @@ public class PASun

return (amTwilightBeginsHour, amTwilightBeginsMin, pmTwilightEndsHour, pmTwilightEndsMin, status);
}

/// <summary>
/// Calculate the equation of time. (The difference between the real Sun time and the mean Sun time.)
/// </summary>
/// <param name="gwdate_day">Greenwich date (day part)</param>
/// <param name="gwdate_month">Greenwich date (month part)</param>
/// <param name="gwdate_year">Greenwich date (year part)</param>
/// <returns>
/// <para>equation_of_time_min -- equation of time (minute part)</para>
/// <para>equation_of_time_sec -- equation of time (seconds part)</para>
/// </returns>
public (double equationOfTimeMin, double equationOfTimeSec) EquationOfTime(double gwdateDay, int gwdateMonth, int gwdateYear)
{
var sunLongitudeDeg = PAMacros.SunLong(12, 0, 0, 0, 0, gwdateDay, gwdateMonth, gwdateYear);
var sunRAHours = PAMacros.DecimalDegreesToDegreeHours(PAMacros.EcRA(sunLongitudeDeg, 0, 0, 0, 0, 0, gwdateDay, gwdateMonth, gwdateYear));
var equivalentUTHours = PAMacros.GreenwichSiderealTimeToUniversalTime(sunRAHours, 0, 0, gwdateDay, gwdateMonth, gwdateYear);
var equationOfTimeHours = equivalentUTHours - 12;

var equationOfTimeMin = PAMacros.DecimalHoursMinute(equationOfTimeHours);
var equationOfTimeSec = PAMacros.DecimalHoursSecond(equationOfTimeHours);

return (equationOfTimeMin, equationOfTimeSec);
}
}
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ If you're interested in this topic, please buy the book! It provides far more de
- [x] Calculate -> Sun's distance and angular size
- [x] Calculate -> Local sunrise and sunset
- [x] Calculate -> Morning and evening twilight
- [ ] Calculate -> Equation of time
- [x] Calculate -> Equation of time
- [ ] Calculate -> Solar elongation

### Planets
Expand Down

0 comments on commit beb9724

Please sign in to comment.