aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/time_with_zone.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/lib/active_support/time_with_zone.rb')
-rw-r--r--activesupport/lib/active_support/time_with_zone.rb14
1 files changed, 10 insertions, 4 deletions
diff --git a/activesupport/lib/active_support/time_with_zone.rb b/activesupport/lib/active_support/time_with_zone.rb
index 9068afef2e..69abb80721 100644
--- a/activesupport/lib/active_support/time_with_zone.rb
+++ b/activesupport/lib/active_support/time_with_zone.rb
@@ -1,4 +1,9 @@
-require 'tzinfo'
+require 'active_support/duration'
+require 'active_support/core_ext/numeric/time'
+require 'active_support/core_ext/integer/time'
+require 'active_support/core_ext/time/conversions'
+require 'active_support/core_ext/date/conversions'
+require 'active_support/core_ext/date_time/conversions'
module ActiveSupport
# A Time-like class that can represent a time in any time zone. Necessary because standard Ruby Time instances are
@@ -92,7 +97,7 @@ module ActiveSupport
alias_method :gmtoff, :utc_offset
def formatted_offset(colon = true, alternate_utc_string = nil)
- utc? && alternate_utc_string || utc_offset.to_utc_offset_s(colon)
+ utc? && alternate_utc_string || TimeZone.seconds_to_utc_offset(utc_offset, colon)
end
# Time uses +zone+ to display the time zone abbreviation, so we're duck-typing it.
@@ -153,8 +158,9 @@ module ActiveSupport
# <tt>:db</tt> format outputs time in UTC; all others output time in local.
# Uses TimeWithZone's +strftime+, so <tt>%Z</tt> and <tt>%z</tt> work correctly.
def to_s(format = :default)
- return utc.to_s(format) if format == :db
- if formatter = ::Time::DATE_FORMATS[format]
+ if format == :db
+ utc.to_s(format)
+ elsif formatter = ::Time::DATE_FORMATS[format]
formatter.respond_to?(:call) ? formatter.call(self).to_s : strftime(formatter)
else
"#{time.strftime("%Y-%m-%d %H:%M:%S")} #{formatted_offset(false, 'UTC')}" # mimicking Ruby 1.9 Time#to_s format