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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3844189bf4a61688714fd85e39a4d617f18650a5
4
- data.tar.gz: ed77ac05becb69df09d68d23d932298adcf51144
3
+ metadata.gz: 2956b5184ecf0ac747d4424632fedd0259833920
4
+ data.tar.gz: 4d5e30bab00c92b96a2a4f2156f86658aca70d95
5
5
  SHA512:
6
- metadata.gz: 48ee8db0feb7569a2c1d0393f8de0df5f82c15388e707ee92d60406db0c92435a2f3ef5684c43197c570df9daeb0fe203a9f702baf4b153ac42f9e602e4f64e7
7
- data.tar.gz: 12cb94d9966d7290bfe7ddbe4aff3e7a6261ae6536bd06a2cc13b11e46383282ed2478fed8a155eca1b908d83ec0a9ad330bc668ed8e3b1d7929f833e69a8cef
6
+ metadata.gz: 955696ff54d8f8788f85b22ffcfb82ad6c8c330637fbf916f876837c1f896e8597ee90520eb6ec2f65cd636f6053e3d4d8d0fd32b48e957f4f48f0b7072680a1
7
+ data.tar.gz: f64b34d918bcbd266370df8c5cc6f71325c099c1adcdd86ea6f3e5636614acfc04688c603617ba91aef78d491d0c1563fbef86f3dd4c05cd3d755e8fc9d37e16
@@ -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(DateTime.now, point)
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(date_time, point)
57
- sunrise_today = sunrise(date_time.to_date, point)
58
- sunset_today = sunset(date_time.to_date, point)
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 date_time >= sunrise_today && date_time < sunset_today
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 = date_time.to_date
65
+ new_date = time.to_date
65
66
  else
66
67
  # Is it before sunrise or after sunset?
67
- if date_time < sunrise_today
68
- new_date = date_time.to_date - 1
68
+ if time < sunrise_today
69
+ new_date = time.to_date - 1
69
70
  else
70
- new_date = date_time.to_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 + (date_time - start).to_f / (finish - start) * 12) * 60 * 60
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
@@ -1,3 +1,3 @@
1
1
  module NewTime
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -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(DateTime.new(2015,month,1,hour,0,0,"+0"), point).to_s
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 = DateTime.new(2015,month,1,hour,0,0,"+0")
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(DateTime.new(2015,month,1,hour,0,0,"+11"), point).to_s
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 = DateTime.new(2015,month,1,hour,0,0,"+11")
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.3
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-31 00:00:00.000000000 Z
11
+ date: 2015-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler