Skip to content

Commit 1576cee

Browse files
committed
Compute the equation of time
The equation of time is the difference of the real Sun time and the mean Sun time. This difference is due to the elliptical shape of the Earth's orbit, and the obliquity of the orbit. `Sun` now has a `#equation_of_time` method that returns an integer: the time difference in seconds. ```rb date = Date.new(2010, 7, 27) Astronoby::Sun.equation_of_time(date: date) ```
1 parent 09e3762 commit 1576cee

File tree

3 files changed

+108
-0
lines changed

3 files changed

+108
-0
lines changed

UPGRADING.md

+4
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ default vertical refraction angle or not.
4040
With a default value of `true`, this new argument will make consider a
4141
default vertical refraction angle or not.
4242

43+
### `Sun::equation_of_time` method added (#40)
44+
45+
Returns the equation of time for a given date.
46+
4347
### `Sun#distance` method added (#30)
4448

4549
Returns the approximate Earth-Sun distance in meters (`Numeric`).

lib/astronoby/bodies/sun.rb

+24
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,30 @@ class Sun
66
ANGULAR_DIAMETER = Angle.as_degrees(0.533128)
77
INTERPOLATION_FACTOR = BigDecimal("24.07")
88

9+
# Source:
10+
# Title: Practical Astronomy with your Calculator or Spreadsheet
11+
# Authors: Peter Duffett-Smith and Jonathan Zwart
12+
# Edition: Cambridge University Press
13+
# Chapter: 51 - The equation of time
14+
15+
# @param date [Date] Requested date
16+
# @return [Integer] Equation of time in seconds
17+
def self.equation_of_time(date:)
18+
noon = Time.utc(date.year, date.month, date.day, 12)
19+
epoch_at_noon = Epoch.from_time(noon)
20+
sun_at_noon = new(epoch: epoch_at_noon)
21+
equatorial_hours = sun_at_noon
22+
.ecliptic_coordinates
23+
.to_equatorial(epoch: epoch_at_noon)
24+
.right_ascension
25+
.hours
26+
gst = GreenwichSiderealTime
27+
.new(date: date, time: equatorial_hours)
28+
.to_utc
29+
30+
(noon - gst).to_i
31+
end
32+
933
# Source:
1034
# Title: Celestial Calculations
1135
# Author: J. L. Lawrence

spec/astronoby/bodies/sun_spec.rb

+80
Original file line numberDiff line numberDiff line change
@@ -572,4 +572,84 @@
572572
# Time from IMCCE: +266° 52′
573573
end
574574
end
575+
576+
describe "::equation_of_time" do
577+
it "returns an Integer" do
578+
date = Date.new
579+
580+
equation_of_time = described_class.equation_of_time(date: date)
581+
582+
expect(equation_of_time).to be_an Integer
583+
end
584+
585+
# Source:
586+
# Title: Practical Astronomy with your Calculator or Spreadsheet
587+
# Authors: Peter Duffett-Smith and Jonathan Zwart
588+
# Edition: Cambridge University Press
589+
# Chapter: 51 - The equation of time
590+
it "returns the right value of 2010-07-27" do
591+
date = Date.new(2010, 7, 27)
592+
593+
equation_of_time = described_class.equation_of_time(date: date)
594+
595+
expect(equation_of_time).to eq(-392)
596+
# Value from Practical Astronomy: 392
597+
end
598+
599+
# Source:
600+
# Title: Celestial Calculations
601+
# Author: J. L. Lawrence
602+
# Edition: MIT Press
603+
# Chapter: 6 - The Sun
604+
it "returns the right value of 2016-05-05" do
605+
date = Date.new(2016, 5, 5)
606+
607+
equation_of_time = described_class.equation_of_time(date: date)
608+
609+
expect(equation_of_time).to eq(199)
610+
# Value from Celestial Calculations: 199
611+
end
612+
613+
# Source:
614+
# Title: Celestial Calculations
615+
# Author: J. L. Lawrence
616+
# Edition: MIT Press
617+
# Chapter: 6 - The Sun
618+
it "returns the right value of 2015-08-09" do
619+
date = Date.new(2015, 8, 9)
620+
621+
equation_of_time = described_class.equation_of_time(date: date)
622+
623+
expect(equation_of_time).to eq(-334)
624+
# Value from Celestial Calculations: 337
625+
end
626+
627+
# Source:
628+
# Title: Celestial Calculations
629+
# Author: J. L. Lawrence
630+
# Edition: MIT Press
631+
# Chapter: 6 - The Sun
632+
it "returns the right value of 2010-05-06" do
633+
date = Date.new(2010, 5, 6)
634+
635+
equation_of_time = described_class.equation_of_time(date: date)
636+
637+
expect(equation_of_time).to eq(201)
638+
# Value from Celestial Calculations: 201
639+
end
640+
641+
# Source:
642+
# Title: Celestial Calculations
643+
# Author: J. L. Lawrence
644+
# Edition: MIT Press
645+
# Chapter: 6 - The Sun
646+
it "returns the right value of 2020-01-01" do
647+
date = Date.new(2020, 1, 1)
648+
649+
equation_of_time = described_class.equation_of_time(date: date)
650+
651+
expect(equation_of_time).to eq(-200)
652+
# Value from Celestial Calculations: 187
653+
end
654+
end
575655
end

0 commit comments

Comments
 (0)