time_difference 0.2.0 → 0.3.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/.travis.yml +0 -1
- data/README.md +15 -1
- data/Rakefile +2 -0
- data/lib/time_difference.rb +13 -1
- data/spec/time_difference_spec.rb +6 -0
- data/time_difference.gemspec +2 -1
- metadata +20 -3
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -23,13 +23,27 @@ And then execute:
|
|
23
23
|
TimeDifference.between(start_time, end_time).in_years
|
24
24
|
=> 1.0
|
25
25
|
|
26
|
-
### Get the time difference in
|
26
|
+
### Get the time difference in months
|
27
27
|
|
28
28
|
start_time = Time.new(2013,1)
|
29
29
|
end_time = Time.new(2014,1)
|
30
30
|
TimeDifference.between(start_time, end_time).in_months
|
31
31
|
=> 12.0
|
32
32
|
|
33
|
+
### Get the time difference for each component
|
34
|
+
|
35
|
+
start_time = Time.new(2013,1)
|
36
|
+
end_time = Time.new(2014,1)
|
37
|
+
TimeDifference.between(start_time, end_time).in_each_component
|
38
|
+
=> {:years=>1.0, :months=>12.0, :weeks=>52.14, :days=>365.0, :hours=>8760.0, :minutes=>525600.0, :seconds=>31536000.0}
|
39
|
+
|
40
|
+
### If you would like a breakdown in each component, use in_general (not that accurate)
|
41
|
+
|
42
|
+
start_time = Time.new(2013,1)
|
43
|
+
end_time = Time.new(2014,1)
|
44
|
+
TimeDifference.between(start_time, end_time).in_general
|
45
|
+
=> {:years=>0, :months=>12, :weeks=>0, :days=>5, :hours=>0, :minutes=>0, :seconds=>0}
|
46
|
+
|
33
47
|
### Supported time difference includes
|
34
48
|
|
35
49
|
in_years
|
data/Rakefile
CHANGED
data/lib/time_difference.rb
CHANGED
@@ -24,9 +24,21 @@ class TimeDifference
|
|
24
24
|
|
25
25
|
end
|
26
26
|
|
27
|
+
def self.in_each_component
|
28
|
+
time_in_each_component = {}
|
29
|
+
[:years, :months, :weeks, :days, :hours, :minutes, :seconds].each do |time_component|
|
30
|
+
if time_component == :months
|
31
|
+
time_in_each_component[time_component] = ((@time_diff/(1.days * 30.42)).round(2)).abs
|
32
|
+
else
|
33
|
+
time_in_each_component[time_component] = ((@time_diff/1.send(time_component)).round(2)).abs
|
34
|
+
end
|
35
|
+
end
|
36
|
+
time_in_each_component
|
37
|
+
end
|
38
|
+
|
27
39
|
def self.in_general
|
28
40
|
result = {}
|
29
|
-
|
41
|
+
[:years, :months, :weeks, :days, :hours, :minutes, :seconds].each do |time_component|
|
30
42
|
result[time_component] = (@time_diff/1.send(time_component)).floor
|
31
43
|
@time_diff = (@time_diff - result[time_component].send(time_component))
|
32
44
|
end
|
@@ -2,6 +2,12 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe TimeDifference do
|
4
4
|
|
5
|
+
it "returns time difference in each component" do
|
6
|
+
start_time = Time.new(2011,1)
|
7
|
+
end_time = Time.new(2011,12)
|
8
|
+
expect(TimeDifference.between(start_time, end_time).in_each_component).to eql({:years=>0.91, :months=>10.98, :weeks=>47.71, :days=>334.0, :hours=>8016.0, :minutes=>480960.0, :seconds=>28857600.0})
|
9
|
+
end
|
10
|
+
|
5
11
|
it "returns time difference in general that matches the total seconds" do
|
6
12
|
start_time = Time.new(2009,9)
|
7
13
|
end_time = Time.new(2010,11)
|
data/time_difference.gemspec
CHANGED
@@ -11,9 +11,10 @@ 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.3.0"
|
15
15
|
|
16
16
|
gem.add_runtime_dependency('activesupport')
|
17
17
|
gem.add_development_dependency('rspec', '~> 2.13.0')
|
18
|
+
gem.add_development_dependency('rake')
|
18
19
|
|
19
20
|
end
|
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.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-09-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -43,6 +43,22 @@ dependencies:
|
|
43
43
|
- - ~>
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: 2.13.0
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rake
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
46
62
|
description: TimeDifference is the missing Ruby method to calculate difference between
|
47
63
|
two given time. You can do a Ruby time difference in year, month, week, day, hour,
|
48
64
|
minute, and seconds.
|
@@ -83,7 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
83
99
|
version: '0'
|
84
100
|
requirements: []
|
85
101
|
rubyforge_project:
|
86
|
-
rubygems_version: 1.8.
|
102
|
+
rubygems_version: 1.8.23
|
87
103
|
signing_key:
|
88
104
|
specification_version: 3
|
89
105
|
summary: TimeDifference is the missing Ruby method to calculate difference between
|
@@ -92,3 +108,4 @@ summary: TimeDifference is the missing Ruby method to calculate difference betwe
|
|
92
108
|
test_files:
|
93
109
|
- spec/spec_helper.rb
|
94
110
|
- spec/time_difference_spec.rb
|
111
|
+
has_rdoc:
|