diff options
author | bUg <aleks.grebennik@gmail.com> | 2012-08-14 20:28:26 +0200 |
---|---|---|
committer | bUg <aleks.grebennik@gmail.com> | 2013-01-04 02:41:09 +0100 |
commit | 38f28dca3aa16efd6cc3af6453f2e6b9e9655ec1 (patch) | |
tree | 3476dcbf018c506499a04ac3523c369dbbb44c96 /activesupport/lib/active_support/core_ext/date_time | |
parent | 4d240ec20a70122b7e69c790a37d2be14e1ff038 (diff) | |
download | rails-38f28dca3aa16efd6cc3af6453f2e6b9e9655ec1.tar.gz rails-38f28dca3aa16efd6cc3af6453f2e6b9e9655ec1.tar.bz2 rails-38f28dca3aa16efd6cc3af6453f2e6b9e9655ec1.zip |
Added ability to compare date/time with infinity
Date, DateTime, Time and TimeWithZone can now be compared to infinity,
so it's now possible to create ranges with one infinite bound and
date/time object as another bound.
Ex.: @range = Range.new(Date.today, Float::INFINITY)
Also it's possible to check inclusion of date/time in range with
conversion.
Ex.: @range.include?(Time.now + 1.year) # => true
@range.include?(DateTime.now + 1.year) # => true
Ability to create date/time ranges with infinite bound is required
for handling postgresql range types.
Diffstat (limited to 'activesupport/lib/active_support/core_ext/date_time')
-rw-r--r-- | activesupport/lib/active_support/core_ext/date_time/calculations.rb | 7 | ||||
-rw-r--r-- | activesupport/lib/active_support/core_ext/date_time/infinite_comparable.rb | 5 |
2 files changed, 5 insertions, 7 deletions
diff --git a/activesupport/lib/active_support/core_ext/date_time/calculations.rb b/activesupport/lib/active_support/core_ext/date_time/calculations.rb index fca5d4d679..4e4852a5e6 100644 --- a/activesupport/lib/active_support/core_ext/date_time/calculations.rb +++ b/activesupport/lib/active_support/core_ext/date_time/calculations.rb @@ -142,11 +142,4 @@ class DateTime def utc_offset (offset * 86400).to_i end - - # Layers additional behavior on DateTime#<=> so that Time and - # ActiveSupport::TimeWithZone instances can be compared with a DateTime. - def <=>(other) - super other.to_datetime - end - end diff --git a/activesupport/lib/active_support/core_ext/date_time/infinite_comparable.rb b/activesupport/lib/active_support/core_ext/date_time/infinite_comparable.rb new file mode 100644 index 0000000000..8a282b19f2 --- /dev/null +++ b/activesupport/lib/active_support/core_ext/date_time/infinite_comparable.rb @@ -0,0 +1,5 @@ +require 'active_support/core_ext/infinite_comparable' + +class DateTime + include InfiniteComparable +end |