Module: ActiveSupport::IncludeTimeWithZone

Included in:
Range
Defined in:
lib/active_support/core_ext/range/include_time_with_zone.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#include?(value) ⇒ Boolean

Extends the default Range#include? to support ActiveSupport::TimeWithZone.

(1.hour.ago..1.hour.from_now).include?(Time.current) # => true

Returns:

  • (Boolean)


12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/active_support/core_ext/range/include_time_with_zone.rb', line 12

def include?(value)
  if self.begin.is_a?(TimeWithZone) || self.end.is_a?(TimeWithZone)
    ActiveSupport::Deprecation.warn(<<-MSG.squish)
      Using `Range#include?` to check the inclusion of a value in
      a date time range is deprecated.
      It is recommended to use `Range#cover?` instead of `Range#include?` to
      check the inclusion of a value in a date time range.
    MSG
    cover?(value)
  else
    super
  end
end