[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Timestamp

Srinivas Sa

11/26/2006 2:41:00 AM

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-....

21 Answers

Srinivas Sa

11/26/2006 3:00:00 AM

0

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-....

KDr2

11/26/2006 7:33:00 AM

0

Srinivas Sa <sr.sakhamuri@gmail.com> 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

Paul Lutus

11/26/2006 9:31:00 AM

0

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.

--
Paul Lutus
http://www.ara...

Srinivas Sa

11/26/2006 1:17:00 PM

0

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-....

Paul Lutus

11/26/2006 6:24:00 PM

0

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?

Here is how to get the components:

a = "23:56:33,9876"

h,m,s,n = a.scan(%r{(\d{2}):(\d{2}):(\d{2}),(\d+)}).flatten

Each of the results is a string, chances are you want to convert them into
integers and then add them up to get a result expressed in seconds:

elapsed = h.to_i * 3600 + m.to_i * 60 + s.to_i

Now you can add or subtract elapsed times using the "elapsed" results.

Then reconvert the elapsed time expressed as an integer into hours, minutes,
and seconds:

s = elapsed % 60

elapsed /= 60

m = elapsed % 60

elapsed /= 60

h = elapsed

>
> 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.

You simply must put up enough code so we can discover your error.

You have posted the line where the error occurs, but not the code that
produces the error and delivered it to that line.

Since you don't seem inclined to post your code, my advice is to start over
and use methods like those shown above.

--
Paul Lutus
http://www.ara...

Jim Cochrane

11/26/2006 6:24:00 PM

0

On 2006-11-26, Srinivas Sa <sr.sakhamuri@gmail.com> 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=define%3A+timestamp&start=0&ie=utf-8&oe=utf-8&client=firefox-a&rls=org.mozilla:en-U...
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.
>
>


--

dblack

11/26/2006 7:02:00 PM

0

Paul Lutus

11/26/2006 7:47:00 PM

0

dblack@wobblini.net 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.

--
Paul Lutus
http://www.ara...

dblack

11/26/2006 8:56:00 PM

0

dblack

11/26/2006 9:00:00 PM

0