Sha256: 02026b8edf6a168a1f399451afd53c5cc66ad9c76a6f9ce5108366becea038f6

Contents?: true

Size: 778 Bytes

Versions: 1

Compression:

Stored size: 778 Bytes

Contents

require "active_support/core_ext/module/attribute_accessors"

module DateAndTime
  module Compatibility
    # If true, +to_time+ preserves the timezone offset of receiver.
    #
    # NOTE: With Ruby 2.4+ the default for +to_time+ changed from
    # converting to the local system time, to preserving the offset
    # of the receiver. For backwards compatibility we're overriding
    # this behavior, but new apps will have an initializer that sets
    # this to true, because the new behavior is preferred.
    mattr_accessor(:preserve_timezone, instance_writer: false) { false }

    def to_time
      if preserve_timezone
        @_to_time_with_instance_offset ||= getlocal(utc_offset)
      else
        @_to_time_with_system_offset ||= getlocal
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
activesupport-5.1.0.beta1 lib/active_support/core_ext/date_and_time/compatibility.rb