activesupport 5.1.3.rc2 → 5.1.3.rc3
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of activesupport might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +35 -0
- data/lib/active_support/duration.rb +51 -6
- data/lib/active_support/gem_version.rb +1 -1
- 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: d3550d00e56db110bf945e6cbcb06f7171b3680c
|
4
|
+
data.tar.gz: c43ac570963c5925edfc76fb1a9ef1a25f24ab01
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b9e53433e2e7ec99f82bbe6c70cbd9df7470c685f817d42c057d6874b50d99e4487d0ac25036d527b9905bb71922f58b09719949e39b97d369d03462d52302c3
|
7
|
+
data.tar.gz: 8f1817c6148dee92d66670d937a710aaf95eeb687d8447949be992ecf99463a02b32c601a3c7b06fc628e49fe258b3a36c9010f56bd8717618942f0ecb7ffa69
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,38 @@
|
|
1
|
+
## Rails 5.1.3.rc3 (July 31, 2017) ##
|
2
|
+
|
3
|
+
* Fix modulo operations involving durations
|
4
|
+
|
5
|
+
Rails 5.1 introduce an `ActiveSupport::Duration::Scalar` class as a wrapper
|
6
|
+
around a numeric value as a way of ensuring a duration was the outcome of
|
7
|
+
an expression. However the implementation was missing support for modulo
|
8
|
+
operations. This support has now been added and should result in a duration
|
9
|
+
being returned from expressions involving modulo operations.
|
10
|
+
|
11
|
+
Prior to Rails 5.1:
|
12
|
+
|
13
|
+
5.minutes % 2.minutes
|
14
|
+
=> 60
|
15
|
+
|
16
|
+
Now:
|
17
|
+
|
18
|
+
5.minutes % 2.minutes
|
19
|
+
=> 1 minute
|
20
|
+
|
21
|
+
Fixes #29603 and #29743.
|
22
|
+
|
23
|
+
*Sayan Chakraborty*, *Andrew White*
|
24
|
+
|
25
|
+
* Fix division where a duration is the denominator
|
26
|
+
|
27
|
+
PR #29163 introduced a change in behavior when a duration was the denominator
|
28
|
+
in a calculation - this was incorrect as dividing by a duration should always
|
29
|
+
return a `Numeric`. The behavior of previous versions of Rails has been restored.
|
30
|
+
|
31
|
+
Fixes #29592.
|
32
|
+
|
33
|
+
*Andrew White*
|
34
|
+
|
35
|
+
|
1
36
|
## Rails 5.1.3.rc2 (July 25, 2017) ##
|
2
37
|
|
3
38
|
* No changes.
|
@@ -74,15 +74,20 @@ module ActiveSupport
|
|
74
74
|
|
75
75
|
def /(other)
|
76
76
|
if Duration === other
|
77
|
-
|
78
|
-
new_value = new_parts.inject(0) { |total, (part, value)| total + value * Duration::PARTS_IN_SECONDS[part] }
|
79
|
-
|
80
|
-
Duration.new(new_value, new_parts)
|
77
|
+
value / other.value
|
81
78
|
else
|
82
79
|
calculate(:/, other)
|
83
80
|
end
|
84
81
|
end
|
85
82
|
|
83
|
+
def %(other)
|
84
|
+
if Duration === other
|
85
|
+
Duration.build(value % other.value)
|
86
|
+
else
|
87
|
+
calculate(:%, other)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
86
91
|
private
|
87
92
|
def calculate(op, other)
|
88
93
|
if Scalar === other
|
@@ -116,6 +121,8 @@ module ActiveSupport
|
|
116
121
|
years: SECONDS_PER_YEAR
|
117
122
|
}.freeze
|
118
123
|
|
124
|
+
PARTS = [:years, :months, :weeks, :days, :hours, :minutes, :seconds].freeze
|
125
|
+
|
119
126
|
attr_accessor :value, :parts
|
120
127
|
|
121
128
|
autoload :ISO8601Parser, "active_support/duration/iso8601_parser"
|
@@ -166,6 +173,30 @@ module ActiveSupport
|
|
166
173
|
new(value * SECONDS_PER_YEAR, [[:years, value]])
|
167
174
|
end
|
168
175
|
|
176
|
+
# Creates a new Duration from a seconds value that is converted
|
177
|
+
# to the individual parts:
|
178
|
+
#
|
179
|
+
# ActiveSupport::Duration.build(31556952).parts # => {:years=>1}
|
180
|
+
# ActiveSupport::Duration.build(2716146).parts # => {:months=>1, :days=>1}
|
181
|
+
#
|
182
|
+
def build(value)
|
183
|
+
parts = {}
|
184
|
+
remainder = value.to_f
|
185
|
+
|
186
|
+
PARTS.each do |part|
|
187
|
+
unless part == :seconds
|
188
|
+
part_in_seconds = PARTS_IN_SECONDS[part]
|
189
|
+
parts[part] = remainder.div(part_in_seconds)
|
190
|
+
remainder = (remainder % part_in_seconds).round(9)
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
parts[:seconds] = remainder
|
195
|
+
parts.reject! { |k, v| v.zero? }
|
196
|
+
|
197
|
+
new(value, parts)
|
198
|
+
end
|
199
|
+
|
169
200
|
private
|
170
201
|
|
171
202
|
def calculate_total_seconds(parts)
|
@@ -232,8 +263,10 @@ module ActiveSupport
|
|
232
263
|
|
233
264
|
# Divides this Duration by a Numeric and returns a new Duration.
|
234
265
|
def /(other)
|
235
|
-
if Scalar === other
|
266
|
+
if Scalar === other
|
236
267
|
Duration.new(value / other.value, parts.map { |type, number| [type, number / other.value] })
|
268
|
+
elsif Duration === other
|
269
|
+
value / other.value
|
237
270
|
elsif Numeric === other
|
238
271
|
Duration.new(value / other, parts.map { |type, number| [type, number / other] })
|
239
272
|
else
|
@@ -241,6 +274,18 @@ module ActiveSupport
|
|
241
274
|
end
|
242
275
|
end
|
243
276
|
|
277
|
+
# Returns the modulo of this Duration by another Duration or Numeric.
|
278
|
+
# Numeric values are treated as seconds.
|
279
|
+
def %(other)
|
280
|
+
if Duration === other || Scalar === other
|
281
|
+
Duration.build(value % other.value)
|
282
|
+
elsif Numeric === other
|
283
|
+
Duration.build(value % other)
|
284
|
+
else
|
285
|
+
raise_type_error(other)
|
286
|
+
end
|
287
|
+
end
|
288
|
+
|
244
289
|
def -@ #:nodoc:
|
245
290
|
Duration.new(-value, parts.map { |type, number| [type, -number] })
|
246
291
|
end
|
@@ -325,7 +370,7 @@ module ActiveSupport
|
|
325
370
|
def inspect #:nodoc:
|
326
371
|
parts.
|
327
372
|
reduce(::Hash.new(0)) { |h, (l, r)| h[l] += r; h }.
|
328
|
-
sort_by { |unit, _ |
|
373
|
+
sort_by { |unit, _ | PARTS.index(unit) }.
|
329
374
|
map { |unit, val| "#{val} #{val == 1 ? unit.to_s.chop : unit.to_s}" }.
|
330
375
|
to_sentence(locale: ::I18n.default_locale)
|
331
376
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activesupport
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.1.3.
|
4
|
+
version: 5.1.3.rc3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Heinemeier Hansson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-07-
|
11
|
+
date: 2017-07-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: i18n
|