Morton Goldberg
12/14/2006 4:44:00 AM
On Dec 13, 2006, at 7:03 PM, Matt G. wrote:
> Sorry for posting a beginner question here, but it seems like date/
> format.rb
> is missing documentation on ruby-doc.org.
>
> So, the question is, why does this code not work? (I'm using
> ruby-1.8.4)
>
> irb(main):001:0> require 'date'
> => true
> irb(main):002:0> myd = DateTime.strptime("1166049481", '%s')
> ArgumentError: 3 elements of civil date are necessary
> from lib/ruby/1.8/date.rb:1214:in `new_with_hash'
> from lib/ruby/1.8/date.rb:1238:in `strptime'
> from (irb):2
>
> I was able to make this work: Date::strptime("1/1/1970", '%d/%m/%
> Y') so I'm
> pretty sure I don't have a syntax error.
DateTime.strptime simply can't handle "1166049481" as an argument. It
wants something that looks like a date/time stamp that a human might
be able to read. Unfortunately, as you point out, exactly what it
wants isn't documented. You're expected to read date/format.rb, which
IMO isn't easy decipher.
BTW, even if your first argument were acceptable, I think your second
would be ignored -- at least in 1.8.2, which is what I'm running, %s
has no effect.
> Thanks for any help.
Not much help, I'm afraid, but you did ask for "any help" :)
Regards, Morton