Time.parse

Discussion in 'Ruby' started by Joel VanderWerf, Jun 16, 2004.

  1. 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")
     
    Joel VanderWerf, Jun 16, 2004
    #1
    1. Advertising

  2. Joel VanderWerf

    daz Guest

    Joel VanderWerf wrote:
    >
    > 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
     
    daz, Jun 17, 2004
    #2
    1. Advertising

  3. Joel VanderWerf

    Mark Hubbart Guest

    On Jun 16, 2004, at 4:28 PM, daz wrote:

    >
    > Joel VanderWerf wrote:
    >>
    >> 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


    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
     
    Mark Hubbart, Jun 17, 2004
    #3
  4. daz wrote:
    > Joel VanderWerf wrote:
    >
    >>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


    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?
     
    Joel VanderWerf, Jun 17, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. flamesrock
    Replies:
    8
    Views:
    477
    Hendrik van Rooyen
    Nov 24, 2006
  2. Replies:
    19
    Views:
    1,136
    Daniel Vallstrom
    Mar 15, 2005
  3. Peter Krantz
    Replies:
    2
    Views:
    197
  4. John Carter

    a=Time.now;(Time.parse(a.to_s)-a)!=0

    John Carter, Oct 26, 2007, in forum: Ruby
    Replies:
    3
    Views:
    156
    ara.t.howard
    Oct 26, 2007
  5. 7stud --

    optparse: parse v. parse! ??

    7stud --, Feb 20, 2008, in forum: Ruby
    Replies:
    3
    Views:
    190
    7stud --
    Feb 20, 2008
Loading...

Share This Page