File: active_support/core_ext/time.rb

Overview
Module Structure
Class Hierarchy
Code

Overview

Module Structure

  module: <Toplevel Module>

Class Hierarchy

Object ( Builtin-Module )
  Time    #4, #41

Code

   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          time.instance_eval do
  19            if defined?(@marshal_with_utc_coercion)
  20              val = remove_instance_variable("@marshal_with_utc_coercion")
  21            end
  22            val ? utc : self
  23          end
  24        end
  25      end
  26 
  27      alias_method :_original_dump, :_dump
  28      def _dump(*args)
  29        obj = dup
  30        obj.instance_variable_set('@marshal_with_utc_coercion', utc?)
  31        obj._original_dump(*args)
  32      end
  33    end
  34  end
  35 
  36  require 'active_support/core_ext/time/behavior'
  37  require 'active_support/core_ext/time/calculations'
  38  require 'active_support/core_ext/time/conversions'
  39  require 'active_support/core_ext/time/zones'
  40 
  41  class Time#:nodoc:
  42    include ActiveSupport::CoreExtensions::Time::Behavior
  43    include ActiveSupport::CoreExtensions::Time::Calculations
  44    include ActiveSupport::CoreExtensions::Time::Conversions
  45    include ActiveSupport::CoreExtensions::Time::Zones
  46  end