Class: SunRiseSet
- Inherits:
-
Object
- Object
- SunRiseSet
- Defined in:
- lib/sunriseset.rb
Overview
Calculates the sun rise and sunset times, with civil, naval and astronomical twilight values. Not sure of the origin of the code. I have seen a fortran version www.srrb.noaa.gov/highlights/sunrise/program.txt a .pl www.mso.anu.edu.au/~brian/grbs/astrosubs.pl and .vb versions too. All had the same comments, so are of a common origin.
Constant Summary collapse
- VERSION =
'0.9.1'
- LATITUDE_DEFAULT =
because I live here
-(36.0 + 59.0/60.0 + 27.60/3600)
- LONGITUDE_DEFAULT =
(174.0 + 29/60.0 + 13.20/3600)
- CIVIL_TWILIGHT =
In degrees from the Zenith. Represents the Time when we turn car lights on and off
96
- NAVAL_TWILIGHT =
In degrees from the Zenith. Represents the Time when we can see the first light (dawn)
102
- ASTRO_TWILIGHT =
In degrees from the Zenith. Represents the Time when the sun is not interfering with viewing distant stars.
108
- SUN_RISE_SET =
0.833 is allowing for the bending in the atmosphere.
90.833
Instance Attribute Summary collapse
-
#astroTwilightEnd ⇒ DateTime
readonly
End of astronomical twilight (sky is now fully dark).
-
#astroTwilightStart ⇒ DateTime
readonly
Naval Twilight begins (Sun is begining to lighten the sky ).
-
#civilTwilightEnd ⇒ DateTime
readonly
End of Civil Twilight.
-
#civilTwilightStart ⇒ DateTime
readonly
Civil Twilight begins.
-
#navalTwilightEnd ⇒ DateTime
readonly
End of naval twilight.
-
#navalTwilightStart ⇒ DateTime
readonly
Naval Twilight begins.
-
#solNoon ⇒ DateTime
readonly
Sun is at the midpoint for today (varies throughout the year).
-
#sunrise ⇒ DateTime
readonly
Sun rise.
-
#sunset ⇒ DateTime
readonly
Sun set.
Class Method Summary collapse
-
.now(latitude = LATITUDE_DEFAULT, longitude = LONGITUDE_DEFAULT) ⇒ SunRiseSet
Constructor for date == today, at location specified.
-
.today(latitude = LATITUDE_DEFAULT, longitude = LONGITUDE_DEFAULT) ⇒ SunRiseSet
Constructor for date == today, at location specified.
Instance Method Summary collapse
-
#initialize(datetime, latitude = LATITUDE_DEFAULT, longitude = LONGITUDE_DEFAULT) ⇒ SunRiseSet
constructor
Constructor for any datetime and location.
-
#to_s ⇒ String
Dumps key attributes as a multiline string.
-
#version ⇒ String
The constant VERSION.
Constructor Details
#initialize(datetime, latitude = LATITUDE_DEFAULT, longitude = LONGITUDE_DEFAULT) ⇒ SunRiseSet
Returns Constructor for any datetime and location.
51 52 53 54 55 56 57 |
# File 'lib/sunriseset.rb', line 51 def initialize(datetime, latitude=LATITUDE_DEFAULT, longitude=LONGITUDE_DEFAULT) @latitude, @longitude = latitude, longitude @julian_date = DateTime.jd(datetime.jd.to_f) @julian_day = @julian_date.jd.to_f #Shorthand for later use, where we want this value as a float. @zone = datetime.offset #datetime.utc_offset/86400 #time zone offset + daylight savings as a fraction of a day calcSun end |
Instance Attribute Details
#astroTwilightEnd ⇒ DateTime (readonly)
Returns end of astronomical twilight (sky is now fully dark).
41 42 43 |
# File 'lib/sunriseset.rb', line 41 def astroTwilightEnd @astroTwilightEnd end |
#astroTwilightStart ⇒ DateTime (readonly)
Returns Naval Twilight begins (Sun is begining to lighten the sky ).
26 27 28 |
# File 'lib/sunriseset.rb', line 26 def astroTwilightStart @astroTwilightStart end |
#civilTwilightEnd ⇒ DateTime (readonly)
Returns End of Civil Twilight.
37 38 39 |
# File 'lib/sunriseset.rb', line 37 def civilTwilightEnd @civilTwilightEnd end |
#civilTwilightStart ⇒ DateTime (readonly)
Returns Civil Twilight begins.
30 31 32 |
# File 'lib/sunriseset.rb', line 30 def civilTwilightStart @civilTwilightStart end |
#navalTwilightEnd ⇒ DateTime (readonly)
Returns end of naval twilight.
39 40 41 |
# File 'lib/sunriseset.rb', line 39 def navalTwilightEnd @navalTwilightEnd end |
#navalTwilightStart ⇒ DateTime (readonly)
Returns Naval Twilight begins.
28 29 30 |
# File 'lib/sunriseset.rb', line 28 def navalTwilightStart @navalTwilightStart end |
#solNoon ⇒ DateTime (readonly)
Returns Sun is at the midpoint for today (varies throughout the year).
44 45 46 |
# File 'lib/sunriseset.rb', line 44 def solNoon @solNoon end |
#sunrise ⇒ DateTime (readonly)
Returns Sun rise.
32 33 34 |
# File 'lib/sunriseset.rb', line 32 def sunrise @sunrise end |
#sunset ⇒ DateTime (readonly)
Returns Sun set.
35 36 37 |
# File 'lib/sunriseset.rb', line 35 def sunset @sunset end |
Class Method Details
.now(latitude = LATITUDE_DEFAULT, longitude = LONGITUDE_DEFAULT) ⇒ SunRiseSet
Returns Constructor for date == today, at location specified.
69 70 71 |
# File 'lib/sunriseset.rb', line 69 def self.now(latitude=LATITUDE_DEFAULT, longitude=LONGITUDE_DEFAULT) self.new(DateTime.now, latitude, longitude) end |
.today(latitude = LATITUDE_DEFAULT, longitude = LONGITUDE_DEFAULT) ⇒ SunRiseSet
Returns Constructor for date == today, at location specified.
62 63 64 |
# File 'lib/sunriseset.rb', line 62 def self.today(latitude=LATITUDE_DEFAULT, longitude=LONGITUDE_DEFAULT) self.new(DateTime.now, latitude, longitude) end |
Instance Method Details
#to_s ⇒ String
Returns dumps key attributes as a multiline string.
74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/sunriseset.rb', line 74 def to_s "Astro Twilight #{@astroTwilightStart.strftime('%H:%M:%S %d-%m')}\n" + "Naval Twilight #{@navalTwilightStart.strftime('%H:%M:%S %d-%m')}\n" + "Civil Twilight #{@civilTwilightStart.strftime('%H:%M:%S %d-%m')}\n" + "Sun Rises #{@sunrise.strftime('%H:%M:%S %d-%m')}\n" + "Solar noon #{@solNoon.strftime('%H:%M:%S %Z %d-%m')}\n" + "Sun Sets #{@sunset.strftime('%H:%M:%S %d-%m')}\n" + "End of Civil Twilight #{@civilTwilightEnd.strftime('%H:%M:%S %d-%m')}\n" + "Naval Twilight #{@navalTwilightEnd.strftime('%H:%M:%S %d-%m')}\n" + "Astro Twilight #{@astroTwilightEnd.strftime('%H:%M:%S %d-%m')}\n" end |
#version ⇒ String
Returns the constant VERSION.
87 88 89 |
# File 'lib/sunriseset.rb', line 87 def version VERSION end |