0

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}
suren
  • 969
  • 4
  • 22
  • Are you genuinely dealing with dates in the era of 111 a.d., or is that a typo? – d11wtq Aug 27 '11 at 07:48
  • Trying it, I think 1.9.2 is able to cope with larger date ranges than 1.8.7. It seems to correctly deal with this date as a date in the 2nd century and switching timezones does some interesting things. – d11wtq Aug 27 '11 at 07:52
  • @d11wtq : it is not typo, my input is 0111 which ruby 187 translate to 2011 (which is what i want) but ruby 192 doesn't, could you plz help. – suren Aug 27 '11 at 10:02
  • I'm not entirely sure how 0111 should logically be interpreted as 2011. It's the year 111. You'll have to pre-process the string if you have no control over the input source. – d11wtq Aug 27 '11 at 10:42

1 Answers1

2

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
d11wtq
  • 34,788
  • 19
  • 120
  • 195