Ruby

Parsing UK dates

If you try to parse a date/time in the form ‘dd/mm/yy hh:mm:ss’ in Ruby 1.8.7, you can get the following:

irb(main):005:0> s = '14/02/07 20:54:19'
=> "14/02/07 20:54:19"
irb(main):006:0> Time.parse(s)
ArgumentError: argument out of range
  from /usr/lib64/ruby/1.8/time.rb:184:in `local'
  from /usr/lib64/ruby/1.8/time.rb:184:in `make_time'
  from /usr/lib64/ruby/1.8/time.rb:243:in `parse'
  from (irb):6

This is because it’s expecting mm/dd/yy (why anyone would want to use such a ridiculous format is anyone’s guess).

Last modified: 10/11/2011 Tags:

Go to top

This website is a personal resource. Nothing here is guaranteed correct or complete, so use at your own risk and try not to delete the Internet. -Stephan

Site Info

Privacy policy

Go to top