Sha256: 6e88b5a5b4ced089bb33fd933eaf83f0e2d0b2a25bd593b06a4fc57657bb1b11

Contents?: true

Size: 845 Bytes

Versions: 17

Compression:

Stored size: 845 Bytes

Contents

# frozen_string_literal: true

require "active_support/core_ext/date_and_time/compatibility"
require "active_support/core_ext/module/redefine_method"

class Time
  include DateAndTime::Compatibility

  silence_redefinition_of_method :to_time

  # Either return +self+ or the time in the local system timezone depending
  # on the setting of +ActiveSupport.to_time_preserves_timezone+.
  def to_time
    preserve_timezone ? self : getlocal
  end

  def preserve_timezone # :nodoc:
    active_support_local_zone == zone || super
  end

  private
    @@active_support_local_tz = nil

    def active_support_local_zone
      @@active_support_local_zone = nil if @@active_support_local_tz != ENV["TZ"]
      @@active_support_local_zone ||=
        begin
          @@active_support_local_tz = ENV["TZ"]
          Time.new.zone
        end
    end
end

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
activesupport-7.2.2 lib/active_support/core_ext/time/compatibility.rb
activesupport-8.0.0.rc2 lib/active_support/core_ext/time/compatibility.rb
activesupport-7.2.1.2 lib/active_support/core_ext/time/compatibility.rb
activesupport-8.0.0.rc1 lib/active_support/core_ext/time/compatibility.rb
activesupport-7.2.1.1 lib/active_support/core_ext/time/compatibility.rb
activesupport-8.0.0.beta1 lib/active_support/core_ext/time/compatibility.rb
omg-activesupport-8.0.0.alpha9 lib/active_support/core_ext/time/compatibility.rb
omg-activesupport-8.0.0.alpha8 lib/active_support/core_ext/time/compatibility.rb
omg-activesupport-8.0.0.alpha7 lib/active_support/core_ext/time/compatibility.rb
omg-activesupport-8.0.0.alpha4 lib/active_support/core_ext/time/compatibility.rb
omg-activesupport-8.0.0.alpha3 lib/active_support/core_ext/time/compatibility.rb
omg-activesupport-8.0.0.alpha2 lib/active_support/core_ext/time/compatibility.rb
omg-activesupport-8.0.0.alpha1 lib/active_support/core_ext/time/compatibility.rb
activesupport-7.2.1 lib/active_support/core_ext/time/compatibility.rb
activesupport-7.2.0 lib/active_support/core_ext/time/compatibility.rb
activesupport-7.2.0.rc1 lib/active_support/core_ext/time/compatibility.rb
activesupport-7.2.0.beta3 lib/active_support/core_ext/time/compatibility.rb