time_difference 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/CHANGELOG.md +5 -2
- data/README.md +1 -1
- data/lib/time_difference.rb +2 -2
- data/spec/time_difference_spec.rb +11 -0
- data/time_difference.gemspec +1 -1
- metadata +1 -1
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
data/lib/time_difference.rb
CHANGED
@@ -14,9 +14,9 @@ class TimeDifference
|
|
14
14
|
self.class.instance_eval do
|
15
15
|
define_method("in_#{time_component}") do
|
16
16
|
if time_component == :months
|
17
|
-
(@time_diff/(1.days * 30.42)).round(2)
|
17
|
+
((@time_diff/(1.days * 30.42)).round(2)).abs
|
18
18
|
else
|
19
|
-
(@time_diff/1.send(time_component)).round(2)
|
19
|
+
((@time_diff/1.send(time_component)).round(2)).abs
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
@@ -19,4 +19,15 @@ describe TimeDifference do
|
|
19
19
|
expect(TimeDifference.between(start_time, end_time).in_minutes).to eql 480960.0
|
20
20
|
end
|
21
21
|
|
22
|
+
it "returns time difference in absolute value regardless how it is minus-ed out" do
|
23
|
+
start_time = Time.new(2011,1)
|
24
|
+
end_time = Time.new(2011,12)
|
25
|
+
expect(TimeDifference.between(end_time, start_time).in_years).to eql 0.91
|
26
|
+
expect(TimeDifference.between(end_time, start_time).in_months).to eql 10.98
|
27
|
+
expect(TimeDifference.between(end_time, start_time).in_weeks).to eql 47.71
|
28
|
+
expect(TimeDifference.between(end_time, start_time).in_days).to eql 334.0
|
29
|
+
expect(TimeDifference.between(end_time, start_time).in_hours).to eql 8016.0
|
30
|
+
expect(TimeDifference.between(end_time, start_time).in_minutes).to eql 480960.0
|
31
|
+
end
|
32
|
+
|
22
33
|
end
|
data/time_difference.gemspec
CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |gem|
|
|
11
11
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
12
12
|
gem.name = "time_difference"
|
13
13
|
gem.require_paths = ["lib"]
|
14
|
-
gem.version = "0.
|
14
|
+
gem.version = "0.2.0"
|
15
15
|
|
16
16
|
gem.add_runtime_dependency('activesupport')
|
17
17
|
gem.add_development_dependency('rspec', '~> 2.13.0')
|