chronic_duration 0.10.5 → 0.10.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 959bf6b04d72c1da1ead272b846f4708775254d4
4
- data.tar.gz: b5b1a908526644ce56ebf19a1dd62c618ccffbc1
3
+ metadata.gz: 69c6a72d2b2392ac29969c76f36831b0e6c684b7
4
+ data.tar.gz: 50aefec89726857b3b1c85e6d89a97222d08f5f7
5
5
  SHA512:
6
- metadata.gz: 55a045f3d94a0b985675d5873ebc7e18d01ae0465e8a8c0c68ae95ffeb9f30cd72f1b43c1a98d0049c3a863201dfc87e436e1cc08cfd001d3daa0f082f3fde27
7
- data.tar.gz: 57f63af3405fc555db755a1310d098d63c66121c86fc98e956d8e2dc1689157a194d02e2ff4a98064efaecca182892bb6b8fee8409a13ed70a3c908e52cfd586
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)
@@ -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 hours >= ChronicDuration.hours_per_day
79
- days = (hours / ChronicDuration.hours_per_day).to_i
80
- hours = (hours % ChronicDuration.hours_per_day).to_i
81
- if opts[:weeks]
82
- if days >= ChronicDuration.days_per_week
83
- weeks = (days / ChronicDuration.days_per_week).to_i
84
- days = (days % ChronicDuration.days_per_week).to_i
85
- if weeks >= 4
86
- months = (weeks / 4).to_i
87
- weeks = (weeks % 4).to_i
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
 
@@ -1,3 +1,3 @@
1
1
  module ChronicDuration
2
- VERSION = '0.10.5'
2
+ VERSION = '0.10.6'
3
3
  end
@@ -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.5
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-07-15 00:00:00.000000000 Z
11
+ date: 2014-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: numerizer