0
- # A Time-like class that can represent a time in any time zone. Necessary because standard Ruby Time instances are
0
+ # A Time-like class that can represent a time in any time zone. Necessary because standard Ruby Time instances are
0
# limited to UTC and the system's <tt>ENV['TZ']</tt> zone.
0
# You shouldn't ever need to create a TimeWithZone instance directly via <tt>new</tt> -- instead, Rails provides the methods
0
@@ -32,12 +32,12 @@ module ActiveSupport
0
def initialize(utc_time, time_zone, local_time = nil, period = nil)
0
@utc, @time_zone, @time = utc_time, time_zone, local_time
0
@period = @utc ? period : get_period_and_ensure_valid_local_time
0
# Returns a Time or DateTime instance that represents the time in +time_zone+.
0
@time ||= period.to_local(@utc)
0
@@ -51,7 +51,7 @@ module ActiveSupport
0
alias_method :getgm, :utc
0
alias_method :getutc, :utc
0
alias_method :gmtime, :utc
0
# Returns the underlying TZInfo::TimezonePeriod.
0
@period ||= time_zone.period_for_utc(@utc)
0
@@ -62,38 +62,38 @@ module ActiveSupport
0
return self if time_zone == new_zone
0
utc.in_time_zone(new_zone)
0
# Returns a <tt>Time.local()</tt> instance of the simultaneous time in your system's <tt>ENV['TZ']</tt> zone
0
alias_method :getlocal, :localtime
0
alias_method :isdst, :dst?
0
time_zone.name == 'UTC'
0
alias_method :gmt?, :utc?
0
period.utc_total_offset
0
alias_method :gmt_offset, :utc_offset
0
alias_method :gmtoff, :utc_offset
0
def formatted_offset(colon = true, alternate_utc_string = nil)
0
utc? && alternate_utc_string || utc_offset.to_utc_offset_s(colon)
0
# Time uses +zone+ to display the time zone abbreviation, so we're duck-typing it.
0
period.zone_identifier.to_s
0
"#{time.strftime('%a, %d %b %Y %H:%M:%S')} #{zone} #{formatted_offset}"
0
@@ -122,7 +122,7 @@ module ActiveSupport
0
%("#{time.strftime("%Y/%m/%d %H:%M:%S")} #{formatted_offset(false)}")
0
def to_yaml(options = {})
0
if options.kind_of?(YAML::Emitter)
0
@@ -130,19 +130,19 @@ module ActiveSupport
0
time.to_yaml(options).gsub('Z', formatted_offset(true, 'Z'))
0
alias_method :rfc822, :rfc2822
0
# <tt>:db</tt> format outputs time in UTC; all others output time in local.
0
# Uses TimeWithZone's +strftime+, so <tt>%Z</tt> and <tt>%z</tt> work correctly.
0
- def to_s(format = :default)
0
+ def to_s(format = :default)
0
return utc.to_s(format) if format == :db
0
if formatter = ::Time::DATE_FORMATS[format]
0
formatter.respond_to?(:call) ? formatter.call(self).to_s : strftime(formatter)
0
@@ -150,27 +150,39 @@ module ActiveSupport
0
"#{time.strftime("%Y-%m-%d %H:%M:%S")} #{formatted_offset(false, 'UTC')}" # mimicking Ruby 1.9 Time#to_s format
0
# Replaces <tt>%Z</tt> and <tt>%z</tt> directives with +zone+ and +formatted_offset+, respectively, before passing to
0
# Time#strftime, so that zone information is correct
0
format = format.gsub('%Z', zone).gsub('%z', formatted_offset(false))
0
# Use the time in UTC for comparisons.
0
# If we're adding a Duration of variable length (i.e., years, months, days), move forward from #time,
0
# otherwise move forward from #utc, for accuracy when moving across DST boundaries
0
@@ -194,7 +206,7 @@ module ActiveSupport
0
result.in_time_zone(time_zone)
0
# If we're adding a Duration of variable length (i.e., years, months, days), move forward from #time,
0
# otherwise move forward from #utc, for accuracy when moving across DST boundaries
0
@@ -204,7 +216,7 @@ module ActiveSupport
0
utc.since(other).in_time_zone(time_zone)
0
@@ -218,7 +230,7 @@ module ActiveSupport
0
utc.advance(options).in_time_zone(time_zone)
0
%w(year mon month day mday hour min sec).each do |method_name|
0
@@ -226,45 +238,45 @@ module ActiveSupport
0
time.respond_to?(:usec) ? time.usec : 0
0
[time.sec, time.min, time.hour, time.day, time.mon, time.year, time.wday, time.yday, dst?, zone]
0
alias_method :hash, :to_i
0
alias_method :tv_sec, :to_i
0
# A TimeWithZone acts like a Time, so just return +self+.
0
utc.to_datetime.new_offset(Rational(utc_offset, 86_400))
0
# So that +self+ <tt>acts_like?(:time)</tt>.
0
# Say we're a Time to thwart type checking.
0
klass == ::Time || super
0
alias_method :kind_of?, :is_a?
0
# Neuter freeze because freezing can cause problems with lazy loading of attributes.
0
@@ -273,7 +285,7 @@ module ActiveSupport
0
[utc, time_zone.name, time]
0
def marshal_load(variables)
0
initialize(variables[0].utc, ::Time.__send__(:get_zone, variables[1]), variables[2].utc)
0
@@ -290,10 +302,10 @@ module ActiveSupport
0
result = time.__send__(sym, *args, &block)
0
result.acts_like?(:time) ? self.class.new(nil, time_zone, result) : result
0
def get_period_and_ensure_valid_local_time
0
- # we don't want a Time.local instance enforcing its own DST rules as well,
0
+ # we don't want a Time.local instance enforcing its own DST rules as well,
0
# so transfer time values to a utc constructor if necessary
0
@time = transfer_time_values_to_utc_constructor(@time) unless @time.utc?
0
@@ -304,11 +316,11 @@ module ActiveSupport
0
def transfer_time_values_to_utc_constructor(time)
0
::Time.utc_time(time.year, time.month, time.day, time.hour, time.min, time.sec, time.respond_to?(:usec) ? time.usec : 0)
0
def duration_of_variable_length?(obj)
0
ActiveSupport::Duration === obj && obj.parts.flatten.detect {|p| [:years, :months, :days].include? p }