Timestamp

Discussion in 'Ruby' started by Srinivas Sa, Nov 26, 2006.

  1. Srinivas Sa

    Srinivas Sa Guest

    How do i add two time stamps

    Time stamps are in the form of HH:MM:DD:SS,nnnn

    Used Time.parse to convert to Time and tried add ts1 + ts2 but it failed
    saying no method.

    tried t1 + t1.to_i i am getting

    irb(main):013:0> p t1 + t2.to_i
    RangeError: time + 1164507831.000000 out of Time range
    from (irb):13:in `+'
    from (irb):13

    can somebody help me out?

    --
    Posted via http://www.ruby-forum.com/.
    Srinivas Sa, Nov 26, 2006
    #1
    1. Advertising

  2. Srinivas Sa

    Srinivas Sa Guest

    My timestamps are HH:MM:SS,nnnn format.. I mentioned wrongly before...

    Srinivas Sa wrote:
    > How do i add two time stamps
    >
    > Time stamps are in the form of HH:MM:DD:SS,nnnn
    >
    > Used Time.parse to convert to Time and tried add ts1 + ts2 but it failed
    > saying no method.
    >
    > tried t1 + t1.to_i i am getting
    >
    > irb(main):013:0> p t1 + t2.to_i
    > RangeError: time + 1164507831.000000 out of Time range
    > from (irb):13:in `+'
    > from (irb):13
    >
    > can somebody help me out?



    --
    Posted via http://www.ruby-forum.com/.
    Srinivas Sa, Nov 26, 2006
    #2
    1. Advertising

  3. Srinivas Sa

    KDr2 Guest

    Srinivas Sa <> writes:

    > My timestamps are HH:MM:SS,nnnn format.. I mentioned wrongly before...
    >
    > Srinivas Sa wrote:
    >> How do i add two time stamps
    >>
    >> Time stamps are in the form of HH:MM:DD:SS,nnnn
    >>
    >> Used Time.parse to convert to Time and tried add ts1 + ts2 but it failed
    >> saying no method.
    >>
    >> tried t1 + t1.to_i i am getting
    >>
    >> irb(main):013:0> p t1 + t2.to_i
    >> RangeError: time + 1164507831.000000 out of Time range
    >> from (irb):13:in `+'
    >> from (irb):13
    >>
    >> can somebody help me out?


    So what do you want to get?
    eg,(the year 2006)+((the year 2007),you want to get (the year 4013)?

    --
    For some reasons,my EMail had been changed to "kdr2[#]163.com" now...

    NO GNUS is Bad News.

    ------yours Killy Draw
    KDr2, Nov 26, 2006
    #3
  4. Srinivas Sa

    Srinivas Sa Guest

    Sorry for not being clear; I am trying to work on merging subtitle files
    which holds the subtitles of a movie. They have the HH:MM:SS,nnn and
    sentence that need to be flashed at that moment on the screen.

    I just need to know how to add up two time stamps so that i can merge
    the two files and make it one continuous sequence of subtitles. E.g.

    00:24:25,700 + 00:00:03,800 should yield 00:24:29,500

    I don't bother what date (YY/MM/DD part) it is gonna be when I add up,
    it can be anything. So overflow is a t

    Or is there a different class I have to use or should I write my own
    logic to do this?

    Thanks in advance

    Paul Lutus wrote:
    > Srinivas Sa wrote:
    >
    >> How do i add two time stamps
    >>
    >> Time stamps are in the form of HH:MM:DD:SS,nnnn
    >>
    >> Used Time.parse to convert to Time and tried add ts1 + ts2 but it failed
    >> saying no method.

    >
    > Saying what? Please paste the code and the exact wording of the error
    > message into your newsreader.
    >
    >> tried t1 + t1.to_i i am getting
    >>
    >> irb(main):013:0> p t1 + t2.to_i
    >> RangeError: time + 1164507831.000000 out of Time range
    >> from (irb):13:in `+'
    >> from (irb):13

    >
    > Of course adding two times near the present would exceed the total range
    > of
    > possible times, between December 31, 1969 (time approx. = 0) and January
    > 18, 2038 (time approx. = (2^31)-1). That is the entire, total range for
    > time variables, and if you try to add two times near the present,
    > November
    > 11, 2006 (time approx. = 1164533263), you will overflow the acceptable
    > range.
    >
    > But this is an obvious error. Why not tell us what you are trying to
    > accomplish?
    >
    >>
    >> can somebody help me out?

    >
    > Sure, no problem, I will be happy to help you out. But first, you need
    > to
    > tell me that you want.
    >
    > Computer programming can be described as telling a computer what you
    > want,
    > in excruciatingly specific terms. Be just as specific in your reply.
    >
    > 1. I want this ____________________
    >
    > 2. But instead, I got this ______________________
    >
    > 3. Here is how (1) and (2) differ from each other _________________
    >
    > You have only described a problem on the way to a goal, but you didn't
    > mention what the goal was.



    --
    Posted via http://www.ruby-forum.com/.
    Srinivas Sa, Nov 26, 2006
    #4
  5. Srinivas Sa

    Jim Cochrane Guest

    On 2006-11-26, Srinivas Sa <> wrote:
    > Sorry for not being clear; I am trying to work on merging subtitle files
    > which holds the subtitles of a movie. They have the HH:MM:SS,nnn and
    > sentence that need to be flashed at that moment on the screen.
    >
    > I just need to know how to add up two time stamps so that i can merge
    > the two files and make it one continuous sequence of subtitles. E.g.
    >
    > 00:24:25,700 + 00:00:03,800 should yield 00:24:29,500


    Those appear to be durations, not time stamps - you want to add 24 min,
    25 sec and change to 3 min and change, right? If so, you should be
    looking for a class that deals with time durations (time intervals).

    (first result of:
    http://www.google.com/search?q=defi...ient=firefox-a&rls=org.mozilla:en-US:official
    A timestamp is the current time of an event that is recorded by a computer.
    )

    >
    > I don't bother what date (YY/MM/DD part) it is gonna be when I add up,
    > it can be anything. So overflow is a t
    >
    > Or is there a different class I have to use or should I write my own
    > logic to do this?
    >
    > Thanks in advance
    >
    > Paul Lutus wrote:
    >> Srinivas Sa wrote:
    >>
    >>> How do i add two time stamps
    >>>
    >>> Time stamps are in the form of HH:MM:DD:SS,nnnn
    >>>
    >>> Used Time.parse to convert to Time and tried add ts1 + ts2 but it failed
    >>> saying no method.

    >>
    >> Saying what? Please paste the code and the exact wording of the error
    >> message into your newsreader.
    >>
    >>> tried t1 + t1.to_i i am getting
    >>>
    >>> irb(main):013:0> p t1 + t2.to_i
    >>> RangeError: time + 1164507831.000000 out of Time range
    >>> from (irb):13:in `+'
    >>> from (irb):13

    >>
    >> Of course adding two times near the present would exceed the total range
    >> of
    >> possible times, between December 31, 1969 (time approx. = 0) and January
    >> 18, 2038 (time approx. = (2^31)-1). That is the entire, total range for
    >> time variables, and if you try to add two times near the present,
    >> November
    >> 11, 2006 (time approx. = 1164533263), you will overflow the acceptable
    >> range.
    >>
    >> But this is an obvious error. Why not tell us what you are trying to
    >> accomplish?
    >>
    >>>
    >>> can somebody help me out?

    >>
    >> Sure, no problem, I will be happy to help you out. But first, you need
    >> to
    >> tell me that you want.
    >>
    >> Computer programming can be described as telling a computer what you
    >> want,
    >> in excruciatingly specific terms. Be just as specific in your reply.
    >>
    >> 1. I want this ____________________
    >>
    >> 2. But instead, I got this ______________________
    >>
    >> 3. Here is how (1) and (2) differ from each other _________________
    >>
    >> You have only described a problem on the way to a goal, but you didn't
    >> mention what the goal was.

    >
    >



    --
    Jim Cochrane, Nov 26, 2006
    #5
  6. Srinivas Sa

    Guest

    Hi --

    On Mon, 27 Nov 2006, Paul Lutus wrote:

    > Srinivas Sa wrote:
    >
    >> Sorry for not being clear; I am trying to work on merging subtitle files
    >> which holds the subtitles of a movie. They have the HH:MM:SS,nnn and
    >> sentence that need to be flashed at that moment on the screen.

    >
    > Break it down for us. What does ",nnn" signify?


    Fractions of a second:

    irb(main):020:0> Time.parse("10:53:44,12") + 0.87
    => Sun Nov 26 10:53:44 -0500 2006
    irb(main):021:0> Time.parse("10:53:44,12") + 0.88
    => Sun Nov 26 10:53:45 -0500 2006


    David

    --
    David A. Black |
    Author of "Ruby for Rails" [1] | Ruby/Rails training & consultancy [3]
    DABlog (DAB's Weblog) [2] | Co-director, Ruby Central, Inc. [4]
    [1] http://www.manning.com/black | [3] http://www.rubypowerandlight.com
    [2] http://dablog.rubypal.com | [4] http://www.rubycentral.org
    , Nov 26, 2006
    #6
  7. Srinivas Sa

    Guest

    Hi --

    On Mon, 27 Nov 2006, Paul Lutus wrote:

    > wrote:
    >
    >> Hi --
    >>
    >> On Mon, 27 Nov 2006, Paul Lutus wrote:
    >>
    >>> Srinivas Sa wrote:
    >>>
    >>>> Sorry for not being clear; I am trying to work on merging subtitle files
    >>>> which holds the subtitles of a movie. They have the HH:MM:SS,nnn and
    >>>> sentence that need to be flashed at that moment on the screen.
    >>>
    >>> Break it down for us. What does ",nnn" signify?

    >>
    >> Fractions of a second:
    >>
    >> irb(main):020:0> Time.parse("10:53:44,12") + 0.87
    >> => Sun Nov 26 10:53:44 -0500 2006
    >> irb(main):021:0> Time.parse("10:53:44,12") + 0.88
    >> => Sun Nov 26 10:53:45 -0500 2006

    >
    > Milliseconds, then, since they appeared as three-digit integers.


    Actually the whole thing (44,12 or 23,555 or whatever) is one float,
    using a comma separator instead of a dot. The comma is the
    "preferred" separator in this context in the ISO 8601 standard, so I
    imagine that's being followed here.


    David

    --
    David A. Black |
    Author of "Ruby for Rails" [1] | Ruby/Rails training & consultancy [3]
    DABlog (DAB's Weblog) [2] | Co-director, Ruby Central, Inc. [4]
    [1] http://www.manning.com/black | [3] http://www.rubypowerandlight.com
    [2] http://dablog.rubypal.com | [4] http://www.rubycentral.org
    , Nov 26, 2006
    #7
  8. Srinivas Sa

    Guest

    Hi --

    On Sun, 26 Nov 2006, Srinivas Sa wrote:

    > My timestamps are HH:MM:SS,nnnn format.. I mentioned wrongly before...
    >
    > Srinivas Sa wrote:
    >> How do i add two time stamps
    >>
    >> Time stamps are in the form of HH:MM:DD:SS,nnnn
    >>
    >> Used Time.parse to convert to Time and tried add ts1 + ts2 but it failed
    >> saying no method.
    >>
    >> tried t1 + t1.to_i i am getting
    >>
    >> irb(main):013:0> p t1 + t2.to_i
    >> RangeError: time + 1164507831.000000 out of Time range
    >> from (irb):13:in `+'
    >> from (irb):13
    >>
    >> can somebody help me out?


    You might find it interesting to look into some of the date/time
    extensions in ActiveSupport, the utility library that ships with
    Rails. You get things like:

    20.hours # 72000 (# of seconds in 20 hours)


    David

    --
    David A. Black |
    Author of "Ruby for Rails" [1] | Ruby/Rails training & consultancy [3]
    DABlog (DAB's Weblog) [2] | Co-director, Ruby Central, Inc. [4]
    [1] http://www.manning.com/black | [3] http://www.rubypowerandlight.com
    [2] http://dablog.rubypal.com | [4] http://www.rubycentral.org
    , Nov 26, 2006
    #8
  9. Srinivas Sa

    Hal Fulton Guest

    Paul Lutus wrote:
    > wrote:
    >
    > / ...
    >
    >
    >>>Milliseconds, then, since they appeared as three-digit integers.

    >>
    >>Actually the whole thing (44,12 or 23,555 or whatever) is one float,
    >>using a comma separator instead of a dot. The comma is the
    >>"preferred" separator in this context in the ISO 8601 standard, so I
    >>imagine that's being followed here.

    >
    >
    > Not that I have any doubt about your claim, but I find it hard to believe
    > that an international standard would specify a locale-specific radix
    > character.
    >


    It does seem odd, but I've seen so much oddness come from committees
    that I can't be totally disbelieving.


    Hal
    Hal Fulton, Nov 26, 2006
    #9
  10. Srinivas Sa

    Guest

    Hi --

    On Mon, 27 Nov 2006, Paul Lutus wrote:

    > wrote:
    >
    > / ...
    >
    >>> Milliseconds, then, since they appeared as three-digit integers.

    >>
    >> Actually the whole thing (44,12 or 23,555 or whatever) is one float,
    >> using a comma separator instead of a dot. The comma is the
    >> "preferred" separator in this context in the ISO 8601 standard, so I
    >> imagine that's being followed here.

    >
    > Not that I have any doubt about your claim, but I find it hard to believe
    > that an international standard would specify a locale-specific radix
    > character.


    I'm not sure what the distinction is between doubting and finding it
    hard to believe :) Anyway, here's a quote from ISO 8601:

    >>>

    If necessary for a particular application a decimal fraction of hour,
    minute or second may be included. If a decimal fraction is included,
    lower order components (if any) shall be omitted and the decimal
    fraction shall be divided from the integer part by the decimal sign
    specified in ISO 31-0: i.e. the comma [,] or full stop [.]. Of these,
    the comma is the preferred sign.
    <<<

    I'm not a big ISO 8601 expert, but I assume that this (or its
    antecedents) are at the root of Ruby's accepting the comma (via a C
    library or otherwise -- I haven't looked closely).


    David

    --
    David A. Black |
    Author of "Ruby for Rails" [1] | Ruby/Rails training & consultancy [3]
    DABlog (DAB's Weblog) [2] | Co-director, Ruby Central, Inc. [4]
    [1] http://www.manning.com/black | [3] http://www.rubypowerandlight.com
    [2] http://dablog.rubypal.com | [4] http://www.rubycentral.org
    , Nov 26, 2006
    #10
  11. Srinivas Sa

    Hal Fulton Guest

    wrote:
    >
    > I'm not sure what the distinction is between doubting and finding it
    > hard to believe :) Anyway, here's a quote from ISO 8601:
    >


    Haha... there are many things that I don't doubt but find
    hard to believe in, such as quantum mechanics, the democratic
    process, and true love.


    Hal
    Hal Fulton, Nov 26, 2006
    #11
  12. Srinivas Sa

    Pit Capitain Guest

    [OT] Re: Timestamp

    Paul Lutus schrieb:
    > wrote:
    >> Actually the whole thing (44,12 or 23,555 or whatever) is one float,
    >> using a comma separator instead of a dot. The comma is the
    >> "preferred" separator in this context in the ISO 8601 standard, so I
    >> imagine that's being followed here.

    >
    > Not that I have any doubt about your claim, but I find it hard to believe
    > that an international standard would specify a locale-specific radix
    > character.


    Paul, what would you think to be a better separator, and why?

    Regards,
    Pit
    Pit Capitain, Nov 27, 2006
    #12
  13. Srinivas Sa

    Guest

    Hi --

    On Mon, 27 Nov 2006, Paul Lutus wrote:

    > wrote:
    >
    >> Hi --
    >>
    >> On Mon, 27 Nov 2006, Paul Lutus wrote:
    >>
    >>> wrote:
    >>>
    >>> / ...
    >>>
    >>>>> Milliseconds, then, since they appeared as three-digit integers.
    >>>>
    >>>> Actually the whole thing (44,12 or 23,555 or whatever) is one float,
    >>>> using a comma separator instead of a dot. The comma is the
    >>>> "preferred" separator in this context in the ISO 8601 standard, so I
    >>>> imagine that's being followed here.
    >>>
    >>> Not that I have any doubt about your claim, but I find it hard to believe
    >>> that an international standard would specify a locale-specific radix
    >>> character.

    >>
    >> I'm not sure what the distinction is between doubting and finding it
    >> hard to believe :)

    >
    > Okay, fair enough. I don't doubt that Bush is president, but I find it hard
    > to believe. That should do it. :)


    Yes, I see :)

    >> Anyway, here's a quote from ISO 8601:
    >>
    >>>>>

    >> If necessary for a particular application a decimal fraction of hour,
    >> minute or second may be included. If a decimal fraction is included,
    >> lower order components (if any) shall be omitted and the decimal
    >> fraction shall be divided from the integer part by the decimal sign
    >> specified in ISO 31-0: i.e. the comma [,] or full stop [.]. Of these,
    >> the comma is the preferred sign.

    >
    > This sounds as though the radix sign should follow the locale, as do numbers
    > in that locale.


    It sounds to me like the comma is preferred over the dot, period :)
    But either is OK.


    David

    --
    David A. Black |
    Author of "Ruby for Rails" [1] | Ruby/Rails training & consultancy [3]
    DABlog (DAB's Weblog) [2] | Co-director, Ruby Central, Inc. [4]
    [1] http://www.manning.com/black | [3] http://www.rubypowerandlight.com
    [2] http://dablog.rubypal.com | [4] http://www.rubycentral.org
    , Nov 27, 2006
    #13
  14. Srinivas Sa

    Pit Capitain Guest

    Re: [OT] Re: Timestamp

    Paul Lutus schrieb:
    > Pit Capitain wrote:
    >> Paul, what would you think to be a better separator, and why?

    >
    > Anything but a separator that depends on locale. A separate field, for
    > example, one separated by a tab or any other character. Something like
    > that. (...)


    Paul, thanks for the clarification.

    Regards,
    Pit
    Pit Capitain, Nov 28, 2006
    #14
    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. Manzoorul Hassan

    Convert to NTP Timestamp

    Manzoorul Hassan, Mar 11, 2005, in forum: Perl
    Replies:
    1
    Views:
    2,706
    Jim Gibson
    Mar 11, 2005
  2. Shawn

    displaying sybase timestamp

    Shawn, Jan 27, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    3,146
    Shawn
    Jan 27, 2004
  3. Greg Collins [MVP]

    File Timestamp and Saving Transformed XML to Server

    Greg Collins [MVP], Jul 8, 2004, in forum: ASP .Net
    Replies:
    6
    Views:
    462
    Greg Collins [MVP]
    Jul 12, 2004
  4. Roger Twomey

    Using SQL Server Timestamp

    Roger Twomey, Sep 10, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    23,756
    Greg Burns
    Sep 10, 2004
  5. =?Utf-8?B?bXliYXBweQ==?=
    Replies:
    7
    Views:
    13,061
    =?Utf-8?B?Zng=?=
    Oct 20, 2004
Loading...

Share This Page