time_difference 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
- ## v0.0.1
1
+ ## v0.2.0
2
+ * Time difference will return absolute value
2
3
 
3
- * First release at v0.0.1, here we go!
4
+ ## v0.1.0
5
+
6
+ * First release at v0.1.0, here we go!
data/README.md CHANGED
@@ -8,7 +8,7 @@ TimeDifference is the missing Ruby method to calculate difference between two gi
8
8
 
9
9
  Add this line to your application's Gemfile:
10
10
 
11
- gem 'time_difference', git: 'git@github.com:tmlee/time_difference.git'
11
+ gem 'time_difference'
12
12
 
13
13
  And then execute:
14
14
 
@@ -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
@@ -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.1.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')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: time_difference
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: