Time.parse

J

Joel VanderWerf

Time.parse is documented in ri, but doesn't seem to be defined. Do I
need to require something from the stdlib?

I'm looking for an easy way to convert things like "4:30" to relative
values--seconds since "00:00:00". I can just parse manually, of course,
but was hoping for a standard way to do it, like

Time.parse("4:30") - Time.parse("0:00")
 
D

daz

Joel said:
Time.parse is documented in ri, but doesn't seem to be defined. Do I
need to require something from the stdlib?

I'm looking for an easy way to convert things like "4:30" to relative
values--seconds since "00:00:00". I can just parse manually, of course,
but was hoping for a standard way to do it, like

Time.parse("4:30") - Time.parse("0:00")

Seems that it's an extension of the Time class by time.rb:

require 'time'
p Time.parse("4:30") - Time.parse("0:00")

#=> 16200.0


daz
 
M

Mark Hubbart

Seems that it's an extension of the Time class by time.rb:

require 'time'
p Time.parse("4:30") - Time.parse("0:00")

#=> 16200.0

I've had trouble with something like this before... would it be
conceivable that RDoc could be made to add a note to each piece of ri
documentation saying what file it is defined in? I think this could be
especially useful when looking up methods that are added to the Kernel
or Object, or tacked in the Math module.

cheers,
Mark
 
J

Joel VanderWerf

daz said:
Seems that it's an extension of the Time class by time.rb:

require 'time'
p Time.parse("4:30") - Time.parse("0:00")

#=> 16200.0

Nice and easy. Thanks!

Next question:

irb(main):008:0> Time.parse("sljhfslf")
=> Wed Jun 16 17:31:44 PDT 2004

That's the same as Time.now. But ri Time.parse says:

ArgumentError is raised if ParseDate cannot extract information
from +date+ or Time class cannot represent specified date.

Is there any other way to validate a time?
 

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

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top