when_sun 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +2 -0
- data/VERSION +1 -1
- data/lib/when_sun.rb +25 -9
- data/test/test_when_sun.rb +5 -0
- data/when_sun.gemspec +2 -2
- metadata +4 -4
data/README.rdoc
CHANGED
@@ -4,6 +4,8 @@ WhenSun is a RubyGem for calculating the sunrise and sunset for locations based
|
|
4
4
|
|
5
5
|
This gem is based on https://github.com/joeyates/ruby-sun-times implementation of http://williams.best.vwh.net/sunrise_sunset_algorithm.htm
|
6
6
|
|
7
|
+
Note: Currently this gem is only being tested against Ruby 1.8.6. If you are using a different version please run the unit tests against it and patch as needed.
|
8
|
+
|
7
9
|
== Contributing to when_sun
|
8
10
|
|
9
11
|
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/lib/when_sun.rb
CHANGED
@@ -87,16 +87,10 @@ class WhenSun
|
|
87
87
|
local_mean_time = suns_local_hour_hours + sun_right_ascension_hours - (0.06571 * approximate_time) - 6.622
|
88
88
|
|
89
89
|
# UT = T - lngHour
|
90
|
-
gmt_hours = local_mean_time - longitude_hour
|
91
|
-
gmt_hours -= 24.0 if gmt_hours > 24
|
92
|
-
gmt_hours += 24.0 if gmt_hours < 0
|
93
90
|
|
94
|
-
|
95
|
-
hour_remainder = (gmt_hours.to_f - hour.to_f) * 60.0
|
96
|
-
minute = hour_remainder.floor
|
97
|
-
seconds = (hour_remainder - minute) * 60.0
|
91
|
+
local_mean_time %= 24
|
98
92
|
|
99
|
-
|
93
|
+
return (date.to_datetime() +(local_mean_time - longitude_hour)/24).to_time
|
100
94
|
end
|
101
95
|
|
102
96
|
private
|
@@ -120,5 +114,27 @@ class WhenSun
|
|
120
114
|
end
|
121
115
|
d
|
122
116
|
end
|
123
|
-
|
117
|
+
end
|
118
|
+
|
119
|
+
|
120
|
+
#Backporting some ruby 1.9 stuff. #TODO: Ensure this works on 1.9.2 and turn this patch off for 1.9.2
|
121
|
+
Date::HALF_DAYS_IN_DAY = Rational(1, 2)
|
122
|
+
class Date
|
123
|
+
def to_datetime()
|
124
|
+
DateTime.new!(jd_to_ajd(jd, 0, 0), @of, @sg)
|
125
|
+
end
|
126
|
+
|
127
|
+
def jd_to_ajd(jd, fr, of=0)
|
128
|
+
jd + fr - of - HALF_DAYS_IN_DAY
|
129
|
+
end
|
130
|
+
end
|
131
|
+
class DateTime
|
132
|
+
def to_time
|
133
|
+
d = new_offset(0)
|
134
|
+
d.instance_eval do
|
135
|
+
Time.utc(year, mon, mday, hour, min, sec,
|
136
|
+
(sec_fraction * 86400000000).to_i)
|
137
|
+
end.
|
138
|
+
getlocal
|
139
|
+
end
|
124
140
|
end
|
data/test/test_when_sun.rb
CHANGED
@@ -36,4 +36,9 @@ class TestWhenSun < Test::Unit::TestCase
|
|
36
36
|
assert_raise(RuntimeError) { WhenSun.calculate(:foo, Date.new(2010, 3, 8), 43.779, 11.432) }
|
37
37
|
end
|
38
38
|
|
39
|
+
def test_sunset_should_be_greater_than_sunrise
|
40
|
+
rise = WhenSun.rise(Date.new(2011, 8, 22), 37.38605170, -122.08385110)
|
41
|
+
set = WhenSun.set(Date.new(2011, 8, 22), 37.38605170, -122.08385110)
|
42
|
+
assert_operator(set, '>', rise)
|
43
|
+
end
|
39
44
|
end
|
data/when_sun.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{when_sun}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Eric Cranston"]
|
12
|
-
s.date = %q{2011-08-
|
12
|
+
s.date = %q{2011-08-22}
|
13
13
|
s.description = %q{WhenSun is a RubyGem for calculating the sunrise and sunset for locations based on the date, latitude and longitude.}
|
14
14
|
s.email = %q{ecranston@enphaseenergy.com}
|
15
15
|
s.extra_rdoc_files = [
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: when_sun
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 2
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Eric Cranston
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-08-
|
18
|
+
date: 2011-08-22 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|