Froze rails gems
[depot.git] / vendor / rails / activesupport / lib / active_support / core_ext / time.rb
1 require 'date'
2 require 'time'
3
4 class Time
5 # Ruby 1.8-cvs and 1.9 define private Time#to_date
6 %w(to_date to_datetime).each do |method|
7 public method if private_instance_methods.include?(method)
8 end
9
10 # Pre-1.9 versions of Ruby have a bug with marshaling Time instances, where utc instances are
11 # unmarshaled in the local zone, instead of utc. We're layering behavior on the _dump and _load
12 # methods so that utc instances can be flagged on dump, and coerced back to utc on load.
13 if RUBY_VERSION < '1.9'
14 class << self
15 alias_method :_original_load, :_load
16 def _load(marshaled_time)
17 time = _original_load(marshaled_time)
18 utc = time.instance_variable_get('@marshal_with_utc_coercion')
19 utc ? time.utc : time
20 end
21 end
22
23 alias_method :_original_dump, :_dump
24 def _dump(*args)
25 obj = self.frozen? ? self.dup : self
26 obj.instance_variable_set('@marshal_with_utc_coercion', utc?)
27 obj._original_dump(*args)
28 end
29 end
30 end
31
32 require 'active_support/core_ext/time/behavior'
33 require 'active_support/core_ext/time/calculations'
34 require 'active_support/core_ext/time/conversions'
35 require 'active_support/core_ext/time/zones'
36
37 class Time#:nodoc:
38 include ActiveSupport::CoreExtensions::Time::Behavior
39 include ActiveSupport::CoreExtensions::Time::Calculations
40 include ActiveSupport::CoreExtensions::Time::Conversions
41 include ActiveSupport::CoreExtensions::Time::Zones
42 end