From: arzezak@... Date: 2019-05-22T21:52:37+00:00 Subject: [ruby-core:92789] [Ruby trunk Bug#15867] Enumerable#minmax inconsistent behavior with Time ranges Issue #15867 has been reported by arzezak (Ariel Rzezak). ---------------------------------------- Bug #15867: Enumerable#minmax inconsistent behavior with Time ranges https://bugs.ruby-lang.org/issues/15867 * Author: arzezak (Ariel Rzezak) * Status: Open * Priority: Normal * Assignee: * Target version: * ruby -v: ruby 2.6.2p47 (2019-03-13 revision 67232) [x86_64-darwin17] * Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN ---------------------------------------- With `Date` the behavior is consistent for inclusive and exclusive ranges: ``` >> (Date.new(2019, 7, 1)..Date.new(2019, 7, 3)).min => # >> (Date.new(2019, 7, 1)..Date.new(2019, 7, 3)).max => # >> (Date.new(2019, 7, 1)..Date.new(2019, 7, 3)).minmax => [#, #] >> (Date.new(2019, 7, 1)...Date.new(2019, 7, 3)).minmax => [#, #] ``` With `Time` and inclusive ranges `min` and `max` are returned. ``` >> (Time.new(2019, 7, 1, 10)..Time.new(2019, 7, 1, 12)).min => 2019-07-01 10:00:00 -0300 >> (Time.new(2019, 7, 1, 10)..Time.new(2019, 7, 1, 12)).max => 2019-07-01 12:00:00 -0300 ``` But `minmax` raises a `TypeError`: ``` Traceback (most recent call last): 6: from /Users/ariel/.rbenv/versions/2.6.2/bin/irb:23:in `
' 5: from /Users/ariel/.rbenv/versions/2.6.2/bin/irb:23:in `load' 4: from /Users/ariel/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/irb-1.0.0/exe/irb:11:in `' 3: from (irb):8 2: from (irb):8:in `minmax' 1: from (irb):8:in `each' TypeError (can't iterate from Time) ``` For exclusive ranges `min` is returned but `max` raises. ``` >> (Time.new(2019, 7, 1, 10)...Time.new(2019, 7, 1, 12)).min => 2019-07-01 10:00:00 -0300 >> (Time.new(2019, 7, 1, 10)...Time.new(2019, 7, 1, 12)).max Traceback (most recent call last): 7: from /Users/ariel/.rbenv/versions/2.6.2/bin/irb:23:in `
' 6: from /Users/ariel/.rbenv/versions/2.6.2/bin/irb:23:in `load' 5: from /Users/ariel/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/irb-1.0.0/exe/irb:11:in `' 4: from (irb):11 3: from (irb):11:in `max' 2: from (irb):11:in `max' 1: from (irb):11:in `each' TypeError (can't iterate from Time) ``` If `min` and `max` are returned for an inclusive `Time` range, shouldn't `minmax` be returned as well? Thanks! -- https://bugs.ruby-lang.org/ Unsubscribe: