ruby-duration 3.1.0 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZTQzZmEyYTE0Y2IzNzQ0MjE1OTM2YmRjMjI1OThmMDBlZDIwM2RiMw==
5
+ data.tar.gz: !binary |-
6
+ ZjNjODE1MzJkZGQxOWFjZWFlOTgzZWM2ZWZlM2I2MTBmNjQ0NzQ2Zg==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ NWQzYTRhZTViNzEyYzcxMTZjNzQxNWIzNDI1YThmM2E5MmYxZTk5YzE1ZTZi
10
+ YzQxY2RmZDA4NWRhOTE4MTk1Y2FjODY3OGNmYzgxMDgzNTQ2MjllY2VmMzZi
11
+ MGYzODY1OTU3ZjU3NzE0YmNiYjRlNjQ2NjI4NGNmOGRhMjFhYjI=
12
+ data.tar.gz: !binary |-
13
+ ZDFiMzI1MTg3MWY0MjJlMGY1MmVmYzQ3MGE2OTllYzE2ZTYzNDY2ODdlMjI4
14
+ M2NmOWM2MjkyYzMzMGQ5ODJkYjAzOWIxMzk5YzBkMmRhNjQ1YmMzMWMxYWVl
15
+ M2VlZTk5NTMxMzAyY2RlNWY1NmNhMmU5MjZiNTM5Y2JkNDlmYzQ=
data/lib/duration.rb CHANGED
@@ -90,18 +90,22 @@ class Duration
90
90
  # Formats a duration in ISO8601.
91
91
  # @see http://en.wikipedia.org/wiki/ISO_8601#Durations
92
92
  def iso8601
93
- output = 'P'
94
-
95
- number_of_days = weeks * 7 + days
96
- output << "#{number_of_days}D" if number_of_days > 0
97
- if seconds > 0 || minutes > 0 || hours > 0
98
- output << 'T'
99
- output << "#{hours}H" if hours > 0
100
- output << "#{minutes}M" if minutes > 0
101
- output << "#{seconds}S" if seconds > 0
102
- end
93
+ if present?
94
+ output = 'P'
95
+
96
+ number_of_days = weeks * 7 + days
97
+ output << "#{number_of_days}D" if number_of_days > 0
98
+ if seconds > 0 || minutes > 0 || hours > 0
99
+ output << 'T'
100
+ output << "#{hours}H" if hours > 0
101
+ output << "#{minutes}M" if minutes > 0
102
+ output << "#{seconds}S" if seconds > 0
103
+ end
103
104
 
104
- output
105
+ negative? ? "-#{output}" : output
106
+ else
107
+ 'PT0S'
108
+ end
105
109
  end
106
110
 
107
111
  # @return true if total is 0
@@ -114,6 +118,10 @@ class Duration
114
118
  !blank?
115
119
  end
116
120
 
121
+ def negative?
122
+ @negative
123
+ end
124
+
117
125
  # Format a duration into a human-readable string.
118
126
  #
119
127
  # %w => weeks
@@ -210,7 +218,8 @@ private
210
218
  def calculate!
211
219
  multiples = [MULTIPLES[:weeks], MULTIPLES[:days], MULTIPLES[:hours], MULTIPLES[:minutes], MULTIPLES[:seconds]]
212
220
  units = []
213
- @total = @seconds.to_f.round
221
+ @negative = @seconds < 0
222
+ @total = @seconds.abs.to_f.round
214
223
  multiples.inject(@total) do |total, multiple|
215
224
  # Divide into largest unit
216
225
  units << total / multiple
@@ -1,3 +1,3 @@
1
1
  class Duration
2
- VERSION = "3.1.0"
2
+ VERSION = "3.2.0"
3
3
  end
@@ -23,7 +23,7 @@ Gem::Specification.new do |s|
23
23
  s.add_development_dependency "yard", ">= 0"
24
24
  s.add_development_dependency "rake", ">= 0"
25
25
  s.add_development_dependency "simplecov", ">= 0.3.5"
26
- s.add_development_dependency "mongoid", ">= 3.0.0"
26
+ s.add_development_dependency "mongoid", ">= 3.0.0", "< 4.0.0"
27
27
 
28
28
  s.files = `git ls-files`.split("\n")
29
29
  s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
data/test/helper.rb CHANGED
@@ -10,6 +10,8 @@ end
10
10
 
11
11
  $LOAD_PATH.unshift(File.dirname(__FILE__))
12
12
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
13
- require 'ruby-duration'
14
13
 
15
- MiniTest.autorun
14
+ require 'i18n'
15
+ I18n.enforce_available_locales = true
16
+
17
+ require 'ruby-duration'
@@ -201,6 +201,18 @@ describe "Duration" do
201
201
  assert_equal "PT1H30S", d.iso8601
202
202
  end
203
203
 
204
+ it 'should format empty duration' do
205
+ d = Duration.new(0)
206
+ assert_equal 'PT0S', d.iso8601
207
+ end
208
+
209
+ it 'should format negative duration' do
210
+ d = Duration.new(-1)
211
+ assert_equal '-PT1S', d.iso8601
212
+
213
+ d = Duration.new(-100)
214
+ assert_equal '-PT1M40S', d.iso8601
215
+ end
204
216
  end
205
217
 
206
218
  describe "utilities methods" do
data/test/test_i18n.rb CHANGED
@@ -9,6 +9,10 @@ describe "I18n" do
9
9
  I18n.locale = :pt
10
10
  end
11
11
 
12
+ after do
13
+ I18n.locale = :en
14
+ end
15
+
12
16
  it "should translate to segundo" do
13
17
  assert_equal "segundo", Duration.new(:second => 1).format("%~s")
14
18
  end
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-duration
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
5
- prerelease:
4
+ version: 3.2.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Jose Peleteiro
@@ -10,12 +9,11 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2013-07-11 00:00:00.000000000 Z
12
+ date: 2014-09-17 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: activesupport
17
16
  requirement: !ruby/object:Gem::Requirement
18
- none: false
19
17
  requirements:
20
18
  - - ! '>='
21
19
  - !ruby/object:Gem::Version
@@ -23,7 +21,6 @@ dependencies:
23
21
  type: :runtime
24
22
  prerelease: false
25
23
  version_requirements: !ruby/object:Gem::Requirement
26
- none: false
27
24
  requirements:
28
25
  - - ! '>='
29
26
  - !ruby/object:Gem::Version
@@ -31,7 +28,6 @@ dependencies:
31
28
  - !ruby/object:Gem::Dependency
32
29
  name: i18n
33
30
  requirement: !ruby/object:Gem::Requirement
34
- none: false
35
31
  requirements:
36
32
  - - ! '>='
37
33
  - !ruby/object:Gem::Version
@@ -39,7 +35,6 @@ dependencies:
39
35
  type: :runtime
40
36
  prerelease: false
41
37
  version_requirements: !ruby/object:Gem::Requirement
42
- none: false
43
38
  requirements:
44
39
  - - ! '>='
45
40
  - !ruby/object:Gem::Version
@@ -47,7 +42,6 @@ dependencies:
47
42
  - !ruby/object:Gem::Dependency
48
43
  name: iso8601
49
44
  requirement: !ruby/object:Gem::Requirement
50
- none: false
51
45
  requirements:
52
46
  - - ! '>='
53
47
  - !ruby/object:Gem::Version
@@ -55,7 +49,6 @@ dependencies:
55
49
  type: :runtime
56
50
  prerelease: false
57
51
  version_requirements: !ruby/object:Gem::Requirement
58
- none: false
59
52
  requirements:
60
53
  - - ! '>='
61
54
  - !ruby/object:Gem::Version
@@ -63,7 +56,6 @@ dependencies:
63
56
  - !ruby/object:Gem::Dependency
64
57
  name: bundler
65
58
  requirement: !ruby/object:Gem::Requirement
66
- none: false
67
59
  requirements:
68
60
  - - ! '>='
69
61
  - !ruby/object:Gem::Version
@@ -71,7 +63,6 @@ dependencies:
71
63
  type: :development
72
64
  prerelease: false
73
65
  version_requirements: !ruby/object:Gem::Requirement
74
- none: false
75
66
  requirements:
76
67
  - - ! '>='
77
68
  - !ruby/object:Gem::Version
@@ -79,7 +70,6 @@ dependencies:
79
70
  - !ruby/object:Gem::Dependency
80
71
  name: minitest
81
72
  requirement: !ruby/object:Gem::Requirement
82
- none: false
83
73
  requirements:
84
74
  - - ! '>='
85
75
  - !ruby/object:Gem::Version
@@ -87,7 +77,6 @@ dependencies:
87
77
  type: :development
88
78
  prerelease: false
89
79
  version_requirements: !ruby/object:Gem::Requirement
90
- none: false
91
80
  requirements:
92
81
  - - ! '>='
93
82
  - !ruby/object:Gem::Version
@@ -95,7 +84,6 @@ dependencies:
95
84
  - !ruby/object:Gem::Dependency
96
85
  name: yard
97
86
  requirement: !ruby/object:Gem::Requirement
98
- none: false
99
87
  requirements:
100
88
  - - ! '>='
101
89
  - !ruby/object:Gem::Version
@@ -103,7 +91,6 @@ dependencies:
103
91
  type: :development
104
92
  prerelease: false
105
93
  version_requirements: !ruby/object:Gem::Requirement
106
- none: false
107
94
  requirements:
108
95
  - - ! '>='
109
96
  - !ruby/object:Gem::Version
@@ -111,7 +98,6 @@ dependencies:
111
98
  - !ruby/object:Gem::Dependency
112
99
  name: rake
113
100
  requirement: !ruby/object:Gem::Requirement
114
- none: false
115
101
  requirements:
116
102
  - - ! '>='
117
103
  - !ruby/object:Gem::Version
@@ -119,7 +105,6 @@ dependencies:
119
105
  type: :development
120
106
  prerelease: false
121
107
  version_requirements: !ruby/object:Gem::Requirement
122
- none: false
123
108
  requirements:
124
109
  - - ! '>='
125
110
  - !ruby/object:Gem::Version
@@ -127,7 +112,6 @@ dependencies:
127
112
  - !ruby/object:Gem::Dependency
128
113
  name: simplecov
129
114
  requirement: !ruby/object:Gem::Requirement
130
- none: false
131
115
  requirements:
132
116
  - - ! '>='
133
117
  - !ruby/object:Gem::Version
@@ -135,7 +119,6 @@ dependencies:
135
119
  type: :development
136
120
  prerelease: false
137
121
  version_requirements: !ruby/object:Gem::Requirement
138
- none: false
139
122
  requirements:
140
123
  - - ! '>='
141
124
  - !ruby/object:Gem::Version
@@ -143,19 +126,23 @@ dependencies:
143
126
  - !ruby/object:Gem::Dependency
144
127
  name: mongoid
145
128
  requirement: !ruby/object:Gem::Requirement
146
- none: false
147
129
  requirements:
148
130
  - - ! '>='
149
131
  - !ruby/object:Gem::Version
150
132
  version: 3.0.0
133
+ - - <
134
+ - !ruby/object:Gem::Version
135
+ version: 4.0.0
151
136
  type: :development
152
137
  prerelease: false
153
138
  version_requirements: !ruby/object:Gem::Requirement
154
- none: false
155
139
  requirements:
156
140
  - - ! '>='
157
141
  - !ruby/object:Gem::Version
158
142
  version: 3.0.0
143
+ - - <
144
+ - !ruby/object:Gem::Version
145
+ version: 4.0.0
159
146
  description: Duration type
160
147
  email:
161
148
  - jose@peleteiro.net
@@ -183,31 +170,27 @@ files:
183
170
  - test/test_mongoid.rb
184
171
  homepage: http://github.com/peleteiro/ruby-duration
185
172
  licenses: []
173
+ metadata: {}
186
174
  post_install_message:
187
175
  rdoc_options:
188
176
  - --charset=UTF-8
189
177
  require_paths:
190
178
  - lib
191
179
  required_ruby_version: !ruby/object:Gem::Requirement
192
- none: false
193
180
  requirements:
194
181
  - - ! '>='
195
182
  - !ruby/object:Gem::Version
196
183
  version: '0'
197
- segments:
198
- - 0
199
- hash: 1867546005898660473
200
184
  required_rubygems_version: !ruby/object:Gem::Requirement
201
- none: false
202
185
  requirements:
203
186
  - - ! '>='
204
187
  - !ruby/object:Gem::Version
205
188
  version: 1.3.6
206
189
  requirements: []
207
190
  rubyforge_project: ruby-duration
208
- rubygems_version: 1.8.25
191
+ rubygems_version: 2.2.2
209
192
  signing_key:
210
- specification_version: 3
193
+ specification_version: 4
211
194
  summary: Duration type
212
195
  test_files: []
213
196
  has_rdoc: