Sha256: 72684599c996f240e105d00e4f4bcbfa515834513330278254077d34e5f28f34

Contents?: true

Size: 592 Bytes

Versions: 6

Compression:

Stored size: 592 Bytes

Contents

# frozen_string_literal: true

# TimeWithZone defines `in_time_zone`
if defined?(ActiveSupport::TimeWithZone)
  require 'forwardable'

  Time.class_eval do
    unless method_defined?(:to_local)
      extend Forwardable

      def_delegators :to_datetime, :to_local
    end
  end

  DateTime.class_eval do
    unless method_defined?(:to_local)
      # Converts to an Eastern time zone
      #
      # @return [DateTime]
      #
      def to_local
        in_time_zone(RubyRailsExtensions.configuration.default_time_zone || 'Eastern Time (US & Canada)').to_datetime
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ruby-rails-extensions-1.1.1 lib/ruby-rails-extensions/extensions/to_local.rb
ruby-rails-extensions-1.1.1.pre.rc.1 lib/ruby-rails-extensions/extensions/to_local.rb
ruby-rails-extensions-0.2.0 lib/ruby-rails-extensions/extensions/to_local.rb
ruby-rails-extensions-0.2.0.pre.rc.1 lib/ruby-rails-extensions/extensions/to_local.rb
ruby-rails-extensions-1.1.0 lib/ruby-rails-extensions/extensions/to_local.rb
ruby-rails-extensions-1.1.0.pre.rc.1 lib/ruby-rails-extensions/extensions/to_local.rb