chronic_duration 0.10.5 → 0.10.6
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 +4 -4
- data/README.md +2 -0
- data/lib/chronic_duration.rb +19 -17
- data/lib/chronic_duration/version.rb +1 -1
- data/spec/lib/chronic_duration_spec.rb +4 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 69c6a72d2b2392ac29969c76f36831b0e6c684b7
|
4
|
+
data.tar.gz: 50aefec89726857b3b1c85e6d89a97222d08f5f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 97b91a6d8d54244d722ad12c9bfc8f7f05ef8553fc49d7997ec3883dafb39c345eb5a592f6a4b0283fd54e72f0ce9faf76798313b85d055aca338c430ac313c9
|
7
|
+
data.tar.gz: bc61ef5ca5ad8aa244fcaa4b6a55c427182d98eb44774822a11af4ceb528c737c35295611d1f57e57cb72b3637b217e2e927a23de34c5b61a18cd0d8210549b6
|
data/README.md
CHANGED
@@ -32,6 +32,8 @@ The reverse can also be accomplished with the output method. So pass in seconds
|
|
32
32
|
=> 2 wks 1 day 1 hr
|
33
33
|
>> ChronicDuration.output(1299600, :weeks => true, :units => 2)
|
34
34
|
=> 2 wks 1 day
|
35
|
+
>> ChronicDuration.output(45*24*60*60 + 15*60, :limit_to_hours => true)
|
36
|
+
=> 1080 hrs 15 mins
|
35
37
|
>> ChronicDuration.output(1299600, :weeks => true, :units => 2, :joiner => ', ')
|
36
38
|
=> 2 wks, 1 day
|
37
39
|
>> ChronicDuration.output(1296000)
|
data/lib/chronic_duration.rb
CHANGED
@@ -75,22 +75,24 @@ module ChronicDuration
|
|
75
75
|
if minutes >= 60
|
76
76
|
hours = (minutes / 60).to_i
|
77
77
|
minutes = (minutes % 60).to_i
|
78
|
-
if
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
if
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
78
|
+
if !opts[:limit_to_hours]
|
79
|
+
if hours >= ChronicDuration.hours_per_day
|
80
|
+
days = (hours / ChronicDuration.hours_per_day).to_i
|
81
|
+
hours = (hours % ChronicDuration.hours_per_day).to_i
|
82
|
+
if opts[:weeks]
|
83
|
+
if days >= ChronicDuration.days_per_week
|
84
|
+
weeks = (days / ChronicDuration.days_per_week).to_i
|
85
|
+
days = (days % ChronicDuration.days_per_week).to_i
|
86
|
+
if weeks >= 4
|
87
|
+
months = (weeks / 4).to_i
|
88
|
+
weeks = (weeks % 4).to_i
|
89
|
+
end
|
90
|
+
end
|
91
|
+
else
|
92
|
+
if days >= 30
|
93
|
+
months = (days / 30).to_i
|
94
|
+
days = (days % 30).to_i
|
88
95
|
end
|
89
|
-
end
|
90
|
-
else
|
91
|
-
if days >= 30
|
92
|
-
months = (days / 30).to_i
|
93
|
-
days = (days % 30).to_i
|
94
96
|
end
|
95
97
|
end
|
96
98
|
end
|
@@ -238,8 +240,8 @@ private
|
|
238
240
|
raise DurationParseError, "An invalid word #{word.inspect} was used in the string to be parsed."
|
239
241
|
end
|
240
242
|
end
|
241
|
-
# add '1' at front if string starts with something recognizable but not with a number, like 'day' or 'minute 30sec'
|
242
|
-
res.unshift(1) if res.length > 0 && mappings[res[0]]
|
243
|
+
# add '1' at front if string starts with something recognizable but not with a number, like 'day' or 'minute 30sec'
|
244
|
+
res.unshift(1) if res.length > 0 && mappings[res[0]]
|
243
245
|
res.join(' ')
|
244
246
|
end
|
245
247
|
|
@@ -201,6 +201,10 @@ describe ChronicDuration do
|
|
201
201
|
ChronicDuration.output(45*24*60*60, :weeks => true).should =~ /.*wk.*/
|
202
202
|
end
|
203
203
|
|
204
|
+
it "returns hours and minutes only when :hours_only option specified" do
|
205
|
+
ChronicDuration.output(395*24*60*60 + 15*60, :limit_to_hours => true).should == '9480 hrs 15 mins'
|
206
|
+
end
|
207
|
+
|
204
208
|
it "returns the specified number of units if provided" do
|
205
209
|
ChronicDuration.output(4 * 3600 + 60 + 1, units: 2).should == '4 hrs 1 min'
|
206
210
|
ChronicDuration.output(6 * 30 * 24 * 3600 + 24 * 3600 + 3600 + 60 + 1, units: 3, format: :long).should == '6 months 1 day 1 hour'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chronic_duration
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.10.
|
4
|
+
version: 0.10.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- hpoydar
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-09-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: numerizer
|