Project

General

Profile

Bug #12981

Updated by kenta-s (Kenta SHIRAI) almost 8 years ago

Date.parse cannot accept incomplete strings whose delimiter is a hyphen like: "2016-12", "2016-11", although it can accept if a delimiter is a slash like: "2016/12" 

 I'm not really sure if this is a bug or an expected behavior, but a maintainer of rails/rails recommended me to report this to Ruby team when I issued a PR( https://github.com/rails/rails/pull/27181 ) to them.    So I'd appreciate if this issue is looked into. 

 steps to reproduce: 

 ~~~ ruby 
 require "date" 
 => true 

 Date.parse("2016/12/01") 
 => #<Date: 2016-12-01 ((2457724j,0s,0n),+0s,2299161j)> 

 Date.parse("2016-12-01") 
 => #<Date: 2016-12-01 ((2457724j,0s,0n),+0s,2299161j)> 

 Date.parse("2016/12") 
 => #<Date: 2016-12-01 ((2457724j,0s,0n),+0s,2299161j)> 

 Date.parse("2016-12") 
 ArgumentError: invalid date 
	 from (irb):3:in `parse' 
	 from (irb):3 
	 from /usr/local/bin/irb:11:in `<main>' 
 ~~~ 

Back