Project

General

Profile

Actions

Feature #15668

open

stdlib: Date - Time should return the difference in days

Added by foonlyboy (Eike Dierks) over 5 years ago. Updated over 5 years ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:91842]

Description

Hi at the ruby/stdlib,

Computing with times and dates is very complicated.
There are so many pitfalls lurking there.

I stumbled about a seemingly simple computation,
involving Date and Time

try:
Date.today - Time.now
=> TypeError: expected numeric

while my naively expected result can done by:
Date.today - Time.now.to_date
=> (0/1)

There must be a whole lot of good reasons why Date - Time is not allowed.

I'd like to suggest:

  • improve the error message
  • improve the documentation of #-

For the error message:
TypeError: expected numeric
should be improved to:
Date - Time is not allowed

The documentation of Date should state why this is so problematic.

You might even want to add a principal documentation,
about the handling of Date and Time in ruby


you can't tune a fish

Actions

Also available in: Atom PDF

Like0
Like0