suren
suren

Reputation: 981

Parsing time in Ruby 1.9.2 is not same as Ruby 1.8.7?

Parsing this in ruby 1.8.7

time_str = "Sun Feb 01 0111 00:00:00 GMT+0530 (IST)"<br />
Time.parse(time_str)<br />
output 
Tue Feb 01 00:00:00 +0530 2011

ruby 1.9.2

time_str = "Sun Feb 01 0111 00:00:00 GMT+0530 (IST)"<br />
Time.parse(time_str)<br />
output <br />
0111-02-01 00:00:00 +0553 

Could you please tell me what exactly the problem is?

Is this something to do with the way Time parsed in ruby 1.9.2 as shown below?

Time.parse(time) {|y| 0 <= y && y < 100 ? (y >= 69 ? y + 1900 : y + 2000) : y}

Upvotes: 0

Views: 660

Answers (1)

d11wtq
d11wtq

Reputation: 35318

Ruby 1.9.2 is giving you the date at 1st February 111 AD (because that's what this date is).

http://www.wolframalpha.com/input/?i=February+1st+111AD%3F. 1.8.7, I assume, was not able to handle Dates that long ago.

Ruby 1.9.2 is doing the correct thing.

If your input is written this way, but it really is supposed to represent the year 2011, then:

  1. The input is incorrectly formatted, as it indicates the year 111AD
  2. You'll have to pre-process the input string to a make it the correct format for parsing

Upvotes: 2

Related Questions