2007-03-18 17:56:12 +01:00
|
|
|
require 'date'
|
|
|
|
require 'time'
|
|
|
|
|
|
|
|
class Time
|
2008-09-07 07:54:05 +02:00
|
|
|
# Ruby 1.8-cvs and 1.9 define private Time#to_date
|
2007-03-18 17:56:12 +01:00
|
|
|
%w(to_date to_datetime).each do |method|
|
|
|
|
public method if private_instance_methods.include?(method)
|
|
|
|
end
|
2008-09-07 07:54:05 +02:00
|
|
|
|
|
|
|
# Pre-1.9 versions of Ruby have a bug with marshaling Time instances, where utc instances are
|
|
|
|
# unmarshaled in the local zone, instead of utc. We're layering behavior on the _dump and _load
|
|
|
|
# methods so that utc instances can be flagged on dump, and coerced back to utc on load.
|
|
|
|
if RUBY_VERSION < '1.9'
|
|
|
|
class << self
|
|
|
|
alias_method :_original_load, :_load
|
|
|
|
def _load(marshaled_time)
|
|
|
|
time = _original_load(marshaled_time)
|
2010-05-25 19:45:45 +02:00
|
|
|
time.instance_eval do
|
|
|
|
if defined?(@marshal_with_utc_coercion)
|
|
|
|
val = remove_instance_variable("@marshal_with_utc_coercion")
|
|
|
|
end
|
|
|
|
val ? utc : self
|
|
|
|
end
|
2008-09-07 07:54:05 +02:00
|
|
|
end
|
|
|
|
end
|
2010-05-25 19:45:45 +02:00
|
|
|
|
2008-09-07 07:54:05 +02:00
|
|
|
alias_method :_original_dump, :_dump
|
|
|
|
def _dump(*args)
|
2010-05-25 19:45:45 +02:00
|
|
|
obj = dup
|
2008-09-07 07:54:05 +02:00
|
|
|
obj.instance_variable_set('@marshal_with_utc_coercion', utc?)
|
|
|
|
obj._original_dump(*args)
|
|
|
|
end
|
|
|
|
end
|
2007-03-18 17:56:12 +01:00
|
|
|
end
|
|
|
|
|
2007-12-21 08:48:59 +01:00
|
|
|
require 'active_support/core_ext/time/behavior'
|
|
|
|
require 'active_support/core_ext/time/calculations'
|
|
|
|
require 'active_support/core_ext/time/conversions'
|
2008-05-18 06:22:34 +02:00
|
|
|
require 'active_support/core_ext/time/zones'
|
2007-01-22 14:43:50 +01:00
|
|
|
|
|
|
|
class Time#:nodoc:
|
2007-12-21 08:48:59 +01:00
|
|
|
include ActiveSupport::CoreExtensions::Time::Behavior
|
2007-01-22 14:43:50 +01:00
|
|
|
include ActiveSupport::CoreExtensions::Time::Calculations
|
|
|
|
include ActiveSupport::CoreExtensions::Time::Conversions
|
2008-05-18 06:22:34 +02:00
|
|
|
include ActiveSupport::CoreExtensions::Time::Zones
|
2007-01-22 14:43:50 +01:00
|
|
|
end
|