relativity 0.0.8 → 0.0.9
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/Changelog.rdoc +4 -0
- data/lib/relativity/day_time/conversions.rb +6 -0
- data/lib/relativity/day_time/new.rb +1 -1
- data/lib/relativity/version.rb +1 -1
- data/lib/relativity/week_time.rb +2 -3
- data/spec/day_time/conversions_spec.rb +25 -1
- data/spec/exception_spec.rb +1 -2
- data/spec/week_time/week_time_spec.rb +2 -2
- metadata +4 -4
data/Changelog.rdoc
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
require 'bigdecimal'
|
|
2
|
+
|
|
1
3
|
module DayTime::Conversions
|
|
2
4
|
|
|
3
5
|
def hours
|
|
@@ -22,6 +24,10 @@ module DayTime::Conversions
|
|
|
22
24
|
[hours, minutes, seconds].map{|e| rjust_2_0(e.to_s)}.join(self.class.default_separator)
|
|
23
25
|
end
|
|
24
26
|
|
|
27
|
+
def self.seconds_since_midnight(hh, mm, ss, nn)
|
|
28
|
+
((hh * 3600) + (mm * 60) + ss + BigDecimal("#{nn}")/1000000000)%(24*3600)
|
|
29
|
+
end
|
|
30
|
+
|
|
25
31
|
private
|
|
26
32
|
|
|
27
33
|
def rjust_2_0(s)
|
|
@@ -21,7 +21,7 @@ module DayTime::New
|
|
|
21
21
|
ss = t.sec
|
|
22
22
|
nn = t.nsec
|
|
23
23
|
end
|
|
24
|
-
@seconds_since_midnight = (
|
|
24
|
+
@seconds_since_midnight = DayTime::Conversions.seconds_since_midnight(hh,mm,ss,nn)
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
private
|
data/lib/relativity/version.rb
CHANGED
data/lib/relativity/week_time.rb
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
class WeekTime
|
|
2
2
|
|
|
3
|
-
require 'bigdecimal'
|
|
4
3
|
require 'time'
|
|
5
4
|
|
|
6
5
|
attr_reader :seconds_since_sunday_midnight
|
|
@@ -22,8 +21,8 @@ class WeekTime
|
|
|
22
21
|
nn = t.nsec
|
|
23
22
|
end
|
|
24
23
|
|
|
25
|
-
|
|
26
|
-
@seconds_since_sunday_midnight = week_day_d * 24 * 3600 + seconds_since_midnight
|
|
24
|
+
day_time = DayTime.new(hh,mm,ss,nn)
|
|
25
|
+
@seconds_since_sunday_midnight = (week_day_d * 24 * 3600) + day_time.seconds_since_midnight
|
|
27
26
|
end
|
|
28
27
|
|
|
29
28
|
end
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
|
+
require 'bigdecimal/util'
|
|
2
3
|
|
|
3
4
|
describe DayTime do
|
|
4
5
|
|
|
@@ -31,11 +32,34 @@ describe DayTime do
|
|
|
31
32
|
end
|
|
32
33
|
|
|
33
34
|
it "seconds_since_midnight" do
|
|
34
|
-
|
|
35
|
+
subject.seconds_since_midnight # should_not raise_error
|
|
35
36
|
end
|
|
36
37
|
|
|
37
38
|
it "seconds_since_midnight should be BigDecimal" do
|
|
38
39
|
subject.seconds_since_midnight.should be_kind_of(BigDecimal)
|
|
39
40
|
end
|
|
40
41
|
|
|
42
|
+
context "seconds since midnight" do
|
|
43
|
+
|
|
44
|
+
it "zero is correct" do
|
|
45
|
+
DayTime::Conversions.seconds_since_midnight(0,0,0,0).should == "0".to_d
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
it "hours are correct" do
|
|
49
|
+
DayTime::Conversions.seconds_since_midnight(1,0,0,0).should == "3600".to_d
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it "minutes are correct" do
|
|
53
|
+
DayTime::Conversions.seconds_since_midnight(0,1,0,0).should == "60".to_d
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it "seconds are correct" do
|
|
57
|
+
DayTime::Conversions.seconds_since_midnight(0,0,1,0).should == "1".to_d
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it "nanoseconds are correct" do
|
|
61
|
+
DayTime::Conversions.seconds_since_midnight(0,0,0,1000).should == "0.000001".to_d
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
end
|
|
41
65
|
end
|
data/spec/exception_spec.rb
CHANGED
|
@@ -21,8 +21,7 @@ module Relativity
|
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
it "InvalidRangeFormatError accepts a hash with separator" do
|
|
24
|
-
|
|
25
|
-
should_not raise_error
|
|
24
|
+
Relativity::InvalidRangeFormatError.new(:separator => "abcd") #should_not raise_error
|
|
26
25
|
end
|
|
27
26
|
|
|
28
27
|
it "InvalidRangeFormatError gives a tailured message" do
|
|
@@ -3,11 +3,11 @@ require 'spec_helper'
|
|
|
3
3
|
describe WeekTime do
|
|
4
4
|
|
|
5
5
|
it "new builds a WeekTime" do
|
|
6
|
-
|
|
6
|
+
subject # should_not raise_error
|
|
7
7
|
end
|
|
8
8
|
|
|
9
9
|
it "seconds_since_sunday_midnight" do
|
|
10
|
-
|
|
10
|
+
subject.seconds_since_sunday_midnight # should_not raise_error
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
it "new creates a WeekTime close to now" do
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: relativity
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.9
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -9,11 +9,11 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2012-
|
|
12
|
+
date: 2012-03-01 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: rspec
|
|
16
|
-
requirement: &
|
|
16
|
+
requirement: &79883760 !ruby/object:Gem::Requirement
|
|
17
17
|
none: false
|
|
18
18
|
requirements:
|
|
19
19
|
- - ! '>='
|
|
@@ -21,7 +21,7 @@ dependencies:
|
|
|
21
21
|
version: '2.7'
|
|
22
22
|
type: :development
|
|
23
23
|
prerelease: false
|
|
24
|
-
version_requirements: *
|
|
24
|
+
version_requirements: *79883760
|
|
25
25
|
description: time and time_ranges relative to day, week, month, quarter etc.
|
|
26
26
|
email:
|
|
27
27
|
- peter@vandenabeele.com
|