sun-times 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/{README → README.md} +8 -5
- data/Rakefile +5 -5
- data/lib/sun_times.rb +1 -21
- data/test/calculate_test.rb +6 -27
- metadata +9 -6
data/{README → README.md}
RENAMED
@@ -1,18 +1,21 @@
|
|
1
|
-
|
1
|
+
# SunTimes
|
2
|
+
[![Build Status](https://secure.travis-ci.org/timoschilling/sun-times.png?branch=master)](http://travis-ci.org/timoschilling/sun-times)
|
3
|
+
|
4
|
+
* this is a Fork of [joeyates/ruby-sun-times](https://github.com/joeyates/ruby-sun-times) and is avalible as [sun-times gem](https://rubygems.org/gems/sun-times) so there is no explicit `require` necessary in rails projects *
|
2
5
|
|
3
6
|
Calculates sunrise and sunset times.
|
4
7
|
|
5
|
-
An implementation of the algorithm
|
8
|
+
An implementation of the algorithm described at http://williams.best.vwh.net/sunrise_sunset_algorithm.htm
|
6
9
|
|
7
|
-
|
10
|
+
## References
|
8
11
|
|
9
12
|
* http://www.astro.uu.nl/~strous/AA/en/reken/zonpositie.html - Calculations
|
10
13
|
* http://williams.best.vwh.net/sunrise_sunset_algorithm.htm - Algorithm
|
11
14
|
* http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/264573 - Ken Bloom's implementation
|
12
15
|
|
13
|
-
|
16
|
+
## Licence
|
14
17
|
|
15
|
-
This code is free to use under the terms of the MIT
|
18
|
+
This code is free to use under the terms of the MIT license:
|
16
19
|
|
17
20
|
Copyright (c) 2010 Joe Yates
|
18
21
|
|
data/Rakefile
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
require '
|
3
|
-
require '
|
2
|
+
require 'rubygems/package_task'
|
3
|
+
require 'rdoc/task'
|
4
4
|
require 'rake/testtask'
|
5
5
|
require 'rake/clean'
|
6
6
|
|
7
7
|
$:.unshift(File.dirname(__FILE__) + '/lib')
|
8
8
|
require 'sun_times'
|
9
9
|
|
10
|
-
RDOC_OPTS = ['--quiet', '--title', 'Sun Times Calculator', '--main', 'README', '--inline-source']
|
10
|
+
RDOC_OPTS = ['--quiet', '--title', 'Sun Times Calculator', '--main', 'README.md', '--inline-source']
|
11
11
|
CLEAN.include 'doc'
|
12
12
|
|
13
13
|
task :default => :test
|
@@ -21,6 +21,6 @@ end
|
|
21
21
|
Rake::RDocTask.new do |rdoc|
|
22
22
|
rdoc.rdoc_dir = 'doc/rdoc'
|
23
23
|
rdoc.options += RDOC_OPTS
|
24
|
-
rdoc.main = "README"
|
25
|
-
rdoc.rdoc_files.add ['README', 'COPYING', 'lib/**/*.rb']
|
24
|
+
rdoc.main = "README.md"
|
25
|
+
rdoc.rdoc_files.add ['README.md', 'COPYING', 'lib/**/*.rb']
|
26
26
|
end
|
data/lib/sun_times.rb
CHANGED
@@ -30,7 +30,7 @@ module SunTimes
|
|
30
30
|
module VERSION #:nodoc:
|
31
31
|
MAJOR = 0
|
32
32
|
MINOR = 1
|
33
|
-
TINY =
|
33
|
+
TINY = 4
|
34
34
|
|
35
35
|
STRING = [MAJOR, MINOR, TINY].join('.')
|
36
36
|
end
|
@@ -126,26 +126,6 @@ module SunTimes
|
|
126
126
|
gmt_hours -= 24.0 if gmt_hours > 24
|
127
127
|
gmt_hours += 24.0 if gmt_hours < 0
|
128
128
|
|
129
|
-
case
|
130
|
-
when date.respond_to?( :offset )
|
131
|
-
offset_hours = date.offset * 24
|
132
|
-
when date.respond_to?( :gmt_offset )
|
133
|
-
offset_hours = date.gmt_offset / 3600
|
134
|
-
else
|
135
|
-
offset_hours = nil
|
136
|
-
end
|
137
|
-
|
138
|
-
if ! offset_hours.nil?
|
139
|
-
if gmt_hours + offset_hours < 0
|
140
|
-
next_day = Date.new(date.year, date.month, date.day + 1)
|
141
|
-
return calculate(event, next_day, latitude, longitude, options = {})
|
142
|
-
end
|
143
|
-
if gmt_hours + offset_hours > 24
|
144
|
-
previous_day = Date.new(date.year, date.month, date.day + 1)
|
145
|
-
return calculate(event, previous_day, latitude, longitude, options = {})
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
129
|
hour = gmt_hours.floor
|
150
130
|
hour_remainder = (gmt_hours.to_f - hour.to_f) * 60.0
|
151
131
|
minute = hour_remainder.floor
|
data/test/calculate_test.rb
CHANGED
@@ -2,28 +2,27 @@
|
|
2
2
|
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
3
3
|
require 'test/unit'
|
4
4
|
require 'sun_times'
|
5
|
-
require 'date'
|
6
5
|
|
7
6
|
class SunTimesTest < Test::Unit::TestCase
|
8
7
|
|
9
8
|
def test_rise_20100308_pontassieve
|
10
9
|
rise = SunTimes.calculate(:rise, Date.new(2010, 3, 8), 43.779, 11.432)
|
11
|
-
assert_equal(
|
10
|
+
assert_equal(rise.to_i, 1268026793)
|
12
11
|
end
|
13
12
|
|
14
13
|
def test_set_20100308_pontassieve
|
15
|
-
|
16
|
-
assert_equal(
|
14
|
+
rise = SunTimes.calculate(:set, Date.new(2010, 3, 8), 43.779, 11.432)
|
15
|
+
assert_equal(rise.to_i, 1268068276)
|
17
16
|
end
|
18
17
|
|
19
18
|
def test_rise_helper
|
20
19
|
rise = SunTimes.rise(Date.new(2010, 3, 8), 43.779, 11.432)
|
21
|
-
assert_equal(
|
20
|
+
assert_equal(rise.to_i, 1268026793)
|
22
21
|
end
|
23
22
|
|
24
23
|
def test_set_helper
|
25
|
-
|
26
|
-
assert_equal(
|
24
|
+
rise = SunTimes.set(Date.new(2010, 3, 8), 43.779, 11.432)
|
25
|
+
assert_equal(rise.to_i, 1268068276)
|
27
26
|
end
|
28
27
|
|
29
28
|
def test_midnight_sun_on_20100621_north_cape
|
@@ -37,24 +36,4 @@ class SunTimesTest < Test::Unit::TestCase
|
|
37
36
|
assert_raise(RuntimeError) { SunTimes.calculate(:foo, Date.new(2010, 3, 8), 43.779, 11.432) }
|
38
37
|
end
|
39
38
|
|
40
|
-
def test_time
|
41
|
-
datetime = Time.gm(2010, 6, 13, 0, 0, 0)
|
42
|
-
set = SunTimes.calculate(:set, datetime, 43.779, 11.432)
|
43
|
-
assert_equal(Time.gm(2010, 6, 13, 18, 56, 55), set)
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_datetime
|
47
|
-
datetime = DateTime.new(2010, 6, 13, 0, 0, 0)
|
48
|
-
set = SunTimes.calculate(:set, datetime, 43.779, 11.432)
|
49
|
-
assert_equal(Time.gm(2010, 6, 13, 18, 56, 55), set)
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_respects_timezone_if_supplied
|
53
|
-
pst = DateTime.new(2011, 12, 13, 0, 0, 0, Rational(-8, 24))
|
54
|
-
set = SunTimes.calculate(:set, pst, 45.52, -122.681944)
|
55
|
-
result_datetime = DateTime.new(set.year, set.month, set.day, set.hour, set.min, set.sec, 0)
|
56
|
-
assert(pst < result_datetime)
|
57
|
-
assert(pst + 1 > result_datetime)
|
58
|
-
end
|
59
|
-
|
60
39
|
end
|
metadata
CHANGED
@@ -1,31 +1,34 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sun-times
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Joe Yates
|
9
|
+
- Timo Schilling
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date: 2012-
|
13
|
+
date: 2012-07-12 00:00:00.000000000 Z
|
13
14
|
dependencies: []
|
14
15
|
description:
|
15
|
-
email:
|
16
|
+
email:
|
17
|
+
- joe.g.yates@gmail.com
|
18
|
+
- timo@schilling.io
|
16
19
|
executables: []
|
17
20
|
extensions: []
|
18
21
|
extra_rdoc_files:
|
19
|
-
- README
|
22
|
+
- README.md
|
20
23
|
- COPYING
|
21
24
|
files:
|
22
|
-
- README
|
25
|
+
- README.md
|
23
26
|
- COPYING
|
24
27
|
- Rakefile
|
25
28
|
- lib/sun_times.rb
|
26
29
|
- test/calculate_test.rb
|
27
30
|
- test/test_all.rb
|
28
|
-
homepage: http://github.com/
|
31
|
+
homepage: http://github.com/timoschilling/sun-times
|
29
32
|
licenses: []
|
30
33
|
post_install_message:
|
31
34
|
rdoc_options: []
|