Project

General

Profile

Bug #12273

Time.parse incorrectly parses Russian months

Added by leemour (Viacheslav Ptsarev) almost 4 years ago. Updated almost 4 years ago.

Status:
Rejected
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:74893]

Description

When parsing dates in Russian where day number is 31, Time.parse returns 2016-05-01. No matter what month or year is provided.
31 march 2016:

irb(main):003:0> require "time"
=> true
irb(main):004:0> Time.parse "31 марта 2016"
=> 2016-05-01 00:00:00 +0300
irb(main):005:0> Time.parse "31 march 2016"
=> 2016-03-31 00:00:00 +0300
irb(main):006:0> Time.parse "31 mars 2016"
=> 2016-03-31 00:00:00 +0300

31 december 2013:

irb(main):013:0> Time.parse "31 декабря 2013"
=> 2016-05-01 00:00:00 +0300
irb(main):014:0> Time.parse "31 december 2013"
=> 2013-12-31 00:00:00 +0400

Updated by leemour (Viacheslav Ptsarev) almost 4 years ago

  • Subject changed from Time.parse incorrectly parses 31st days of month in Russian to Time.parse incorrectly parses Russian months

When parsing dates in Russian where day number is 31, Time.parse returns 2016-05-01. No matter what month or year is provided. With other dates, it returns date with given day number, but current month and year.
31 march 2016:

irb(main):003:0> require "time"
=> true
irb(main):004:0> Time.parse "31 марта 2016"
=> 2016-05-01 00:00:00 +0300
irb(main):005:0> Time.parse "31 march 2016"
=> 2016-03-31 00:00:00 +0300
irb(main):006:0> Time.parse "31 mars 2016"
=> 2016-03-31 00:00:00 +0300

31 december 2013:

irb(main):013:0> Time.parse "31 декабря 2013"
=> 2016-05-01 00:00:00 +0300
irb(main):014:0> Time.parse "31 december 2013"
=> 2013-12-31 00:00:00 +0400

22 january 2013:

irb(main):010:0> Time.parse "22 января 2013"
=> 2016-04-22 00:00:00 +0300
irb(main):011:0> Time.parse "22 january 2013"
=> 2013-01-22 00:00:00 +0400

Updated by zverok (Victor Shepelev) almost 4 years ago

I assume Time.parse is not localized to all world languages.
So, it just ignores the "unidentified" part, replacing it with "current month" (and then fixes non-existent 31.04 into 1.05):

Time.parse('31 ничего 2016')
# => 2016-05-01 00:00:00 +0300 
Time.parse('31')
# => 2016-05-01 00:00:00 +0300

Updated by leemour (Viacheslav Ptsarev) almost 4 years ago

Victor Shepelev wrote:

I assume Time.parse is not localized to all world languages.
So, it just ignores the "unidentified" part, replacing it with "current month" (and then fixes non-existent 31.04 into 1.05):

Time.parse('31 ничего 2016')
# => 2016-05-01 00:00:00 +0300 
Time.parse('31')
# => 2016-05-01 00:00:00 +0300

Thanks. So what should I use to parse dates in Russian?

Updated by zverok (Victor Shepelev) almost 4 years ago

Thanks. So what should I use to parse dates in Russian?

There's no easy way, unfortunately. For simple formats you can try to just gsub Russian monthnames into English and then use normal Time.parse.

Not a Ruby bug, definitely :)

Updated by naruse (Yui NARUSE) almost 4 years ago

Viacheslav Ptsarev wrote:

Victor Shepelev wrote:

I assume Time.parse is not localized to all world languages.
So, it just ignores the "unidentified" part, replacing it with "current month" (and then fixes non-existent 31.04 into 1.05):

Time.parse('31 ничего 2016')
# => 2016-05-01 00:00:00 +0300 
Time.parse('31')
# => 2016-05-01 00:00:00 +0300

Thanks. So what should I use to parse dates in Russian?

Just replace Russian to English with gsub before parsing.

Updated by naruse (Yui NARUSE) almost 4 years ago

  • Status changed from Open to Rejected

Also available in: Atom PDF