change string to date error

J

Junkone

i get the following error. wonder why

irb(main):068:0> @@config["date"]
=> "27/12/2007"
irb(main):069:0> Time.parse(@@config["date"])
ArgumentError: argument out of range
from e:/ruby/lib/ruby/1.8/time.rb:184:in `local'
from e:/ruby/lib/ruby/1.8/time.rb:184:in `make_time'
from e:/ruby/lib/ruby/1.8/time.rb:243:in `parse'
from (irb):69
from :0
irb(main):070:0>
 
F

fw

i get the following error. wonder why

irb(main):068:0> @@config["date"]
=> "27/12/2007"
irb(main):069:0> Time.parse(@@config["date"])
ArgumentError: argument out of range
from e:/ruby/lib/ruby/1.8/time.rb:184:in `local'
from e:/ruby/lib/ruby/1.8/time.rb:184:in `make_time'
from e:/ruby/lib/ruby/1.8/time.rb:243:in `parse'
from (irb):69
from :0
irb(main):070:0>

You have the month and day swapped - there's no 27th month in a year:

$ irb
irb(main):001:0> require 'time'
=> true
irb(main):002:0> Time.parse('27/12/2007')
ArgumentError: argument out of range
from /home/felix/ruby1.8.6/lib/ruby/1.8/time.rb:184:in `local'
from /home/felix/ruby1.8.6/lib/ruby/1.8/time.rb:184:in
`make_time'
from /home/felix/ruby1.8.6/lib/ruby/1.8/time.rb:243:in `parse'
from (irb):2
irb(main):003:0> Time.parse('12/27/2007')
=> Thu Dec 27 00:00:00 -0800 2007
irb(main):004:0>


HTH,

Felix
 
J

Junkone

i get the following error. wonder why
irb(main):068:0> @@config["date"]
=> "27/12/2007"
irb(main):069:0> Time.parse(@@config["date"])
ArgumentError: argument out of range
        from e:/ruby/lib/ruby/1.8/time.rb:184:in `local'
        from e:/ruby/lib/ruby/1.8/time.rb:184:in `make_time'
        from e:/ruby/lib/ruby/1.8/time.rb:243:in `parse'
        from (irb):69
        from :0
irb(main):070:0>

You have the month and day swapped - there's no 27th month in a year:

$ irb
irb(main):001:0> require 'time'
=> true
irb(main):002:0> Time.parse('27/12/2007')
ArgumentError: argument out of range
        from /home/felix/ruby1.8.6/lib/ruby/1.8/time.rb:184:in `local'
        from /home/felix/ruby1.8.6/lib/ruby/1.8/time.rb:184:in
`make_time'
        from /home/felix/ruby1.8.6/lib/ruby/1.8/time.rb:243:in `parse'
        from (irb):2
irb(main):003:0> Time.parse('12/27/2007')
=> Thu Dec 27 00:00:00 -0800 2007
irb(main):004:0>

HTH,

Felix

i have a canadian layout and my regional settings on my computer is
set to dd/mm/yyyy. strange that ruby cannot get this one right. all my
office apps and my oracle and mysql databases now recognise this
format on my computer.
 
M

MonkeeSage

i get the following error. wonder why
irb(main):068:0> @@config["date"]
=> "27/12/2007"
irb(main):069:0> Time.parse(@@config["date"])
ArgumentError: argument out of range
from e:/ruby/lib/ruby/1.8/time.rb:184:in `local'
from e:/ruby/lib/ruby/1.8/time.rb:184:in `make_time'
from e:/ruby/lib/ruby/1.8/time.rb:243:in `parse'
from (irb):69
from :0
irb(main):070:0>
You have the month and day swapped - there's no 27th month in a year:
$ irb
irb(main):001:0> require 'time'
=> true
irb(main):002:0> Time.parse('27/12/2007')
ArgumentError: argument out of range
from /home/felix/ruby1.8.6/lib/ruby/1.8/time.rb:184:in `local'
from /home/felix/ruby1.8.6/lib/ruby/1.8/time.rb:184:in
`make_time'
from /home/felix/ruby1.8.6/lib/ruby/1.8/time.rb:243:in `parse'
from (irb):2
irb(main):003:0> Time.parse('12/27/2007')
=> Thu Dec 27 00:00:00 -0800 2007
irb(main):004:0>

Felix

i have a canadian layout and my regional settings on my computer is
set to dd/mm/yyyy. strange that ruby cannot get this one right. all my
office apps and my oracle and mysql databases now recognise this
format on my computer.

Here ya go, eh. ;)

Time.parse(@@config["date"].gsub(/(.*?)\/(.*?)\/(.*)/, '\2/\1/\3'))

Regards,
Jordan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,152
Latest member
LorettaGur
Top