ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:92789] [Ruby trunk Bug#15867] Enumerable#minmax inconsistent behavior with Time ranges
       [not found] <redmine.issue-15867.20190522215237@ruby-lang.org>
@ 2019-05-22 21:52 ` arzezak
  0 siblings, 0 replies; only message in thread
From: arzezak @ 2019-05-22 21:52 UTC (permalink / raw)
  To: ruby-core

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: 2019-07-01 ((2458666j,0s,0n),+0s,2299161j)>
>> (Date.new(2019, 7, 1)..Date.new(2019, 7, 3)).max
=> #<Date: 2019-07-03 ((2458668j,0s,0n),+0s,2299161j)>
>> (Date.new(2019, 7, 1)..Date.new(2019, 7, 3)).minmax
=> [#<Date: 2019-07-01 ((2458666j,0s,0n),+0s,2299161j)>, #<Date: 2019-07-03 ((2458668j,0s,0n),+0s,2299161j)>]
>> (Date.new(2019, 7, 1)...Date.new(2019, 7, 3)).minmax
=> [#<Date: 2019-07-01 ((2458666j,0s,0n),+0s,2299161j)>, #<Date: 2019-07-02 ((2458667j,0s,0n),+0s,2299161j)>]
```

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 `<main>'
        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 `<top (required)>'
        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 `<main>'
        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 `<top (required)>'
        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/

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-05-22 21:52 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <redmine.issue-15867.20190522215237@ruby-lang.org>
2019-05-22 21:52 ` [ruby-core:92789] [Ruby trunk Bug#15867] Enumerable#minmax inconsistent behavior with Time ranges arzezak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).