mirror of
https://github.com/github/rails.git
synced 2026-04-04 03:00:58 -04:00
Refactor Time and DateTime #to_formatted_s: use ternary instead of nested if/else
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8699 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
@@ -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]
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user