aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/duration
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/lib/active_support/duration')
-rw-r--r--activesupport/lib/active_support/duration/iso8601_parser.rb22
-rw-r--r--activesupport/lib/active_support/duration/iso8601_serializer.rb12
2 files changed, 17 insertions, 17 deletions
diff --git a/activesupport/lib/active_support/duration/iso8601_parser.rb b/activesupport/lib/active_support/duration/iso8601_parser.rb
index 12515633fc..3f113b1ef0 100644
--- a/activesupport/lib/active_support/duration/iso8601_parser.rb
+++ b/activesupport/lib/active_support/duration/iso8601_parser.rb
@@ -1,5 +1,5 @@
-require 'strscan'
-require 'active_support/core_ext/regexp'
+require "strscan"
+require "active_support/core_ext/regexp"
module ActiveSupport
class Duration
@@ -12,8 +12,8 @@ module ActiveSupport
class ParsingError < ::ArgumentError; end
PERIOD_OR_COMMA = /\.|,/
- PERIOD = '.'.freeze
- COMMA = ','.freeze
+ PERIOD = ".".freeze
+ COMMA = ",".freeze
SIGN_MARKER = /\A\-|\+|/
DATE_MARKER = /P/
@@ -21,8 +21,8 @@ module ActiveSupport
DATE_COMPONENT = /(\-?\d+(?:[.,]\d+)?)(Y|M|D|W)/
TIME_COMPONENT = /(\-?\d+(?:[.,]\d+)?)(H|M|S)/
- DATE_TO_PART = { 'Y' => :years, 'M' => :months, 'W' => :weeks, 'D' => :days }
- TIME_TO_PART = { 'H' => :hours, 'M' => :minutes, 'S' => :seconds }
+ DATE_TO_PART = { "Y" => :years, "M" => :months, "W" => :weeks, "D" => :days }
+ TIME_TO_PART = { "H" => :hours, "M" => :minutes, "S" => :seconds }
DATE_COMPONENTS = [:years, :months, :days]
TIME_COMPONENTS = [:hours, :minutes, :seconds]
@@ -42,7 +42,7 @@ module ActiveSupport
case mode
when :start
if scan(SIGN_MARKER)
- self.sign = (scanner.matched == '-') ? -1 : 1
+ self.sign = (scanner.matched == "-") ? -1 : 1
self.mode = :sign
else
raise_parsing_error
@@ -99,21 +99,21 @@ module ActiveSupport
# Checks for various semantic errors as stated in ISO 8601 standard.
def validate!
- raise_parsing_error('is empty duration') if parts.empty?
+ raise_parsing_error("is empty duration") if parts.empty?
# Mixing any of Y, M, D with W is invalid.
if parts.key?(:weeks) && (parts.keys & DATE_COMPONENTS).any?
- raise_parsing_error('mixing weeks with other date parts not allowed')
+ raise_parsing_error("mixing weeks with other date parts not allowed")
end
# Specifying an empty T part is invalid.
if mode == :time && (parts.keys & TIME_COMPONENTS).empty?
- raise_parsing_error('time part marker is present but time part is empty')
+ raise_parsing_error("time part marker is present but time part is empty")
end
fractions = parts.values.reject(&:zero?).select { |a| (a % 1) != 0 }
unless fractions.empty? || (fractions.size == 1 && fractions.last == @parts.values.reject(&:zero?).last)
- raise_parsing_error '(only last part can be fractional)'
+ raise_parsing_error "(only last part can be fractional)"
end
return true
diff --git a/activesupport/lib/active_support/duration/iso8601_serializer.rb b/activesupport/lib/active_support/duration/iso8601_serializer.rb
index eb8136e208..542630b950 100644
--- a/activesupport/lib/active_support/duration/iso8601_serializer.rb
+++ b/activesupport/lib/active_support/duration/iso8601_serializer.rb
@@ -1,5 +1,5 @@
-require 'active_support/core_ext/object/blank'
-require 'active_support/core_ext/hash/transform_values'
+require "active_support/core_ext/object/blank"
+require "active_support/core_ext/hash/transform_values"
module ActiveSupport
class Duration
@@ -15,12 +15,12 @@ module ActiveSupport
parts, sign = normalize
return "PT0S".freeze if parts.empty?
- output = 'P'
+ output = "P"
output << "#{parts[:years]}Y" if parts.key?(:years)
output << "#{parts[:months]}M" if parts.key?(:months)
output << "#{parts[:weeks]}W" if parts.key?(:weeks)
output << "#{parts[:days]}D" if parts.key?(:days)
- time = ''
+ time = ""
time << "#{parts[:hours]}H" if parts.key?(:hours)
time << "#{parts[:minutes]}M" if parts.key?(:minutes)
if parts.key?(:seconds)
@@ -41,9 +41,9 @@ module ActiveSupport
p[k] += v unless v.zero?
end
# If all parts are negative - let's make a negative duration
- sign = ''
+ sign = ""
if parts.values.all? { |v| v < 0 }
- sign = '-'
+ sign = "-"
parts.transform_values!(&:-@)
end
[parts, sign]