aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/CHANGELOG2
-rw-r--r--activesupport/lib/active_support/core_ext/date_time/conversions.rb11
-rw-r--r--activesupport/lib/active_support/core_ext/time/conversions.rb11
3 files changed, 6 insertions, 18 deletions
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG
index f7ab486ad7..17cc494e6e 100644
--- a/activesupport/CHANGELOG
+++ b/activesupport/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Refactor Time and DateTime #to_formatted_s: use ternary instead of nested if/else [Geoff Buesing]
+
* Adding Time and DateTime #formatted_offset, for outputting +HH:MM utc offset strings with cross-platform consistency [Geoff Buesing]
* Adding alternate_utc_string option to TimeZone#formatted_offset. Removing unneeded TimeZone#offset. [Geoff Buesing]
diff --git a/activesupport/lib/active_support/core_ext/date_time/conversions.rb b/activesupport/lib/active_support/core_ext/date_time/conversions.rb
index 59d742cde3..fa49c70c90 100644
--- a/activesupport/lib/active_support/core_ext/date_time/conversions.rb
+++ b/activesupport/lib/active_support/core_ext/date_time/conversions.rb
@@ -41,15 +41,8 @@ module ActiveSupport #:nodoc:
# Time::DATE_FORMATS[:month_and_year] = "%B %Y"
# Time::DATE_FORMATS[:short_ordinal] = lambda { |time| time.strftime("%B #{time.day.ordinalize}") }
def to_formatted_s(format = :default)
- if formatter = ::Time::DATE_FORMATS[format]
- if formatter.respond_to?(:call)
- formatter.call(self).to_s
- else
- strftime(formatter)
- end
- else
- to_datetime_default_s
- end
+ return to_default_s unless formatter = ::Time::DATE_FORMATS[format]
+ formatter.respond_to?(:call) ? formatter.call(self).to_s : strftime(formatter)
end
# Returns the utc_offset as an +HH:MM formatted string. Examples:
diff --git a/activesupport/lib/active_support/core_ext/time/conversions.rb b/activesupport/lib/active_support/core_ext/time/conversions.rb
index 466a20c3bc..ab7b009663 100644
--- a/activesupport/lib/active_support/core_ext/time/conversions.rb
+++ b/activesupport/lib/active_support/core_ext/time/conversions.rb
@@ -45,15 +45,8 @@ module ActiveSupport #:nodoc:
# Time::DATE_FORMATS[:month_and_year] = "%B %Y"
# Time::DATE_FORMATS[:short_ordinal] = lambda { |time| time.strftime("%B #{time.day.ordinalize}") }
def to_formatted_s(format = :default)
- if formatter = DATE_FORMATS[format]
- if formatter.respond_to?(:call)
- formatter.call(self).to_s
- else
- strftime(formatter)
- end
- else
- to_default_s
- end
+ return to_default_s unless formatter = DATE_FORMATS[format]
+ formatter.respond_to?(:call) ? formatter.call(self).to_s : strftime(formatter)
end
# Returns the utc_offset as an +HH:MM formatted string. Examples: