Project

General

Profile

Actions

Bug #13036

closed

Date.parse mishandling spanish months "Abril y Agosto"

Added by greutter (Gonzalo Reutter) almost 8 years ago. Updated almost 8 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
[ruby-core:78659]

Description

Steps to reproduce

$ irb

2.3.0 :003 > Date.parse("01-Agosto-2016")
=> 01 Dec 2016
2.3.0 :004 > Date.parse("01-Abril-2016")
=> 01 Dec 2016

Expected behavior

2.3.0 :003 > Date.parse("01-Agosto-2016")
=> 01 Aug 2016
2.3.0 :004 > Date.parse("01-Abril-2016")
=> 01 Apr 2016

Actual behavior

"Agosto" is parsed to December
"Abril" is parsed to December.

System configuration

Ruby 2.3.0

Would much like to fix this myself, should be straight forward, but I'm a hobby developer and have never contributed to a project.

Updated by greutter (Gonzalo Reutter) almost 8 years ago

UPDATE:

I tracked the problem to dates_international.rb (https://gist.github.com/jackrg/2927162)

The problem is solved replacing line 37.

From:

37: month_from = string[/[^\s\d,]+/i]

To:

37: month_from = string[/[a-z]+/i]

Updated by asterite (Ary Borenszweig) almost 8 years ago

I don't think this is a bug, Ruby only parses English month names, it can't possibly try to check all languages in the world. When it can't deduce a month, it uses the current month, which right now is december.

Updated by zverok (Victor Shepelev) almost 8 years ago

AFAIK, Date.parse was NEVER intending to parse anything except English/American dates in English/American formats. Parsing dates internationally is waaaay harder than making dictionaries of month names: different cultures have different (often incompatible) date formats. Take a look at this list, for ex: https://en.wikipedia.org/wiki/Date_format_by_country

International date parser is a cool idea for standalone gem, but I don't think it could be ever expected to be in stdlib.

Updated by greutter (Gonzalo Reutter) almost 8 years ago

Even if Ruby have never intended to parse dates other than English it works quite well parsing Spanish dates. I'm quite confident that it uses dates_international.rb for the magic. I base my belief in the fact that Ruby and that code reproduce the exact same bug, buy defulting to the current month. The the problem is solved by changing line 37 from:

37: month_from = string[/[^\s\d,]+/i]

To:

37: month_from = string[/[a-z]+/i]

I extended the Date class locally to get pass the difficulty. Would like to contribute to the non English speaking Ruby community. Confirming that the suggested solution work for other languages as well and then merging to the main branch.

I would need to know exactly how the library is connected to Ruby in order to try. Help needed.

Updated by shyouhei (Shyouhei Urabe) almost 8 years ago

So is it a dates_international.rb's problem? Then sorry but the ruby's core do not ship that library. You might have obtained a copy of it from somewhere else. Do you remember where? Or, you might want to contact @jackrg directly. Let him know this issue and I hope he can fix it.

Updated by duerst (Martin Dürst) almost 8 years ago

  • Status changed from Open to Rejected

Shyouhei Urabe wrote:

So is it a dates_international.rb's problem?

Yes. But that file has other problems, among else that it only supports four additional languages (French, German, Italian, and Spanish).

Then sorry but the ruby's core do not ship that library.

Yes indeed. I searched the whole Ruby source for a distinctive month name such as "noviembre", but nothing was found.

You might have obtained a copy of it from somewhere else. Do you remember where?

Probably from https://gist.github.com/jackrg/2927162.

Or, you might want to contact @jackrg directly. Let him know this issue and I hope he can fix it.

Already done at the link above (the "let him know", not the "fix").

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0