Project

General

Profile

Feature #17022

Addition of method Kernel#Date

Added by americodls (Americo Duarte) about 1 month ago. Updated about 1 month ago.

Status:
Third Party's Issue
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:99108]

Description

What if we have a method Kernel#Date that delegates to Date.parse? Dates could be written in a more natural way, right?

Date("2020-01-13") - Date("2019-01-13")

Capitalized methods are defined on the Kernel module to facilitate construction of basic types:

Kernel.methods.grep(/^[A-Z].*/)
#=> [:Rational, :Complex, :URI, :Integer, :Float, :String, :Array, :Hash, :Pathname]

Method BigDecimal is added when the corresponding library is required:

require 'bigdecimal'
Kernel.methods.grep(/^[A-Z].*/)
#=> [:Rational, :Complex, :BigDecimal, :URI, :Integer, :Float, :String, :Array, :Hash, :Pathname]

The proposal is to do the same; when we do require 'date', a method Kernel#Date should be added.

Updated by nobu (Nobuyoshi Nakada) about 1 month ago

  • Status changed from Open to Third Party's Issue

Please file at https://github.com/ruby/date.

IMHO, as Date.parse is too heuristic & magical for humans, I don't think we should encourage using it.

#2

Updated by sawa (Tsuyoshi Sawada) about 1 month ago

  • Description updated (diff)

Updated by byroot (Jean Boussier) about 1 month ago

IMHO, as Date.parse is too heuristic & magical for humans

I agree, what about ISO-8601?

Also available in: Atom PDF