new_time 0.0.3 → 0.0.4
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.
- checksums.yaml +4 -4
- data/lib/new_time.rb +13 -12
- data/lib/new_time/version.rb +1 -1
- data/spec/new_time_spec.rb +6 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2956b5184ecf0ac747d4424632fedd0259833920
|
4
|
+
data.tar.gz: 4d5e30bab00c92b96a2a4f2156f86658aca70d95
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 955696ff54d8f8788f85b22ffcfb82ad6c8c330637fbf916f876837c1f896e8597ee90520eb6ec2f65cd636f6053e3d4d8d0fd32b48e957f4f48f0b7072680a1
|
7
|
+
data.tar.gz: f64b34d918bcbd266370df8c5cc6f71325c099c1adcdd86ea6f3e5636614acfc04688c603617ba91aef78d491d0c1563fbef86f3dd4c05cd3d755e8fc9d37e16
|
data/lib/new_time.rb
CHANGED
@@ -12,20 +12,21 @@ module NewTime
|
|
12
12
|
class NewTime
|
13
13
|
attr_accessor :year, :month, :day, :hours, :minutes, :seconds, :fractional
|
14
14
|
|
15
|
+
# TODO Make seconds a float and get rid of fractional
|
15
16
|
def initialize(year, month, day, hours, minutes, seconds, fractional)
|
16
17
|
@year, @month, @day, @hours, @minutes, @seconds, @fractional = year, month, day, hours, minutes, seconds, fractional
|
17
18
|
end
|
18
19
|
|
19
20
|
def self.current_time(point)
|
20
|
-
convert(
|
21
|
+
convert(Time.now, point)
|
21
22
|
end
|
22
23
|
|
23
24
|
def self.sunrise(date, point)
|
24
|
-
SolarEventCalculator.new(date, point.latitude, point.longitude).compute_official_sunrise(point.tz)
|
25
|
+
SolarEventCalculator.new(date, point.latitude, point.longitude).compute_official_sunrise(point.tz).to_time
|
25
26
|
end
|
26
27
|
|
27
28
|
def self.sunset(date, point)
|
28
|
-
SolarEventCalculator.new(date, point.latitude, point.longitude).compute_official_sunset(point.tz)
|
29
|
+
SolarEventCalculator.new(date, point.latitude, point.longitude).compute_official_sunset(point.tz).to_time
|
29
30
|
end
|
30
31
|
|
31
32
|
# Convert back to "normal" time
|
@@ -53,28 +54,28 @@ module NewTime
|
|
53
54
|
start + (new_seconds.to_f / (60 * 60) - new_start_hour) * (finish - start) / 12
|
54
55
|
end
|
55
56
|
|
56
|
-
def self.convert(
|
57
|
-
sunrise_today = sunrise(
|
58
|
-
sunset_today = sunset(
|
57
|
+
def self.convert(time, point)
|
58
|
+
sunrise_today = sunrise(time.to_date, point)
|
59
|
+
sunset_today = sunset(time.to_date, point)
|
59
60
|
|
60
61
|
# During daylight hours?
|
61
|
-
if
|
62
|
+
if time >= sunrise_today && time < sunset_today
|
62
63
|
start, finish = sunrise_today, sunset_today
|
63
64
|
new_start_hour = 6
|
64
|
-
new_date =
|
65
|
+
new_date = time.to_date
|
65
66
|
else
|
66
67
|
# Is it before sunrise or after sunset?
|
67
|
-
if
|
68
|
-
new_date =
|
68
|
+
if time < sunrise_today
|
69
|
+
new_date = time.to_date - 1
|
69
70
|
else
|
70
|
-
new_date =
|
71
|
+
new_date = time.to_date
|
71
72
|
end
|
72
73
|
new_start_hour = 18
|
73
74
|
start = sunset(new_date, point)
|
74
75
|
finish = sunrise(new_date + 1, point)
|
75
76
|
end
|
76
77
|
|
77
|
-
new_seconds = (new_start_hour + (
|
78
|
+
new_seconds = (new_start_hour + (time - start).to_f / (finish - start) * 12) * 60 * 60
|
78
79
|
|
79
80
|
new_fractional = new_seconds - new_seconds.floor
|
80
81
|
new_seconds = new_seconds.floor
|
data/lib/new_time/version.rb
CHANGED
data/spec/new_time_spec.rb
CHANGED
@@ -9,13 +9,13 @@ describe NewTime do
|
|
9
9
|
let(:point) { NewTime::Point.new(51.829731, -0.860455, "Europe/London") }
|
10
10
|
|
11
11
|
def c(month, hour)
|
12
|
-
NewTime::NewTime.convert(
|
12
|
+
NewTime::NewTime.convert(Time.new(2015,month,1,hour,0,0,"+00:00"), point).to_s
|
13
13
|
end
|
14
14
|
|
15
15
|
def i(month, hour)
|
16
|
-
t1 =
|
16
|
+
t1 = Time.new(2015,month,1,hour,0,0,"+00:00")
|
17
17
|
t2 = NewTime::NewTime.convert(t1, point).convert(point)
|
18
|
-
expect(t2).to eq t1
|
18
|
+
expect(t2.to_f).to eq t1.to_f
|
19
19
|
end
|
20
20
|
|
21
21
|
describe ".convert" do
|
@@ -50,13 +50,13 @@ describe NewTime do
|
|
50
50
|
let(:point) { NewTime::Point.new(-33.714955, 150.311407, "Australia/Sydney") }
|
51
51
|
|
52
52
|
def c(month, hour)
|
53
|
-
NewTime::NewTime.convert(
|
53
|
+
NewTime::NewTime.convert(Time.new(2015,month,1,hour,0,0,"+11:00"), point).to_s
|
54
54
|
end
|
55
55
|
|
56
56
|
def i(month, hour)
|
57
|
-
t1 =
|
57
|
+
t1 = Time.new(2015,month,1,hour,0,0,"+11:00")
|
58
58
|
t2 = NewTime::NewTime.convert(t1, point).convert(point)
|
59
|
-
expect(t2).to eq t1
|
59
|
+
expect(t2.to_f).to eq t1.to_f
|
60
60
|
end
|
61
61
|
|
62
62
|
describe ".convert" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: new_time
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Landauer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01
|
11
|
+
date: 2015-02-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|