View previous topic :: View next topic
|
Author |
Message |
bijal.awhad
New User
Joined: 19 Mar 2008 Posts: 51 Location: Pune
|
|
|
|
I'm facing one problem in calculating elapsed time .... I'm describing problem below
1) I've written one program which calculates the difference between file sent time and acknowledgement received time.
**file sent time is the time at which file is sent to ABC interface
**acknowledgement received time is the time at which we receive the acknowledgement from ABC interface.
NOTE:Time format is 24 hrs
**Elapsed time =acknowledgement received time - file sent time
program works fine if file sent time and acknowledgement received time are on same day. For example: say file sent time is 22:07:58(HH:MM:SS) and acknowledgement received time is 23:02:52(HH:MM:SS) then ELAPSED TIME is 00:54:54 (HH:MM:SS) which is correct.
program gives incorrect output if file sent time and acknowledgement received time are on different days.
Foe EXAMPLE: If file sent time is 23:08:47 and acknowledgement received time is 00:14:21(Next day) elapsed time calculated by program is 22:54:26 which is wrong......
Can anybody suggest me how to tackle this problem |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
take the day into account when calculating elapsed time. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
Quote: |
elapsed time calculated by program is 22:54:26 which is wrong...... |
is wrong because the algorithm or the implementation is wrong
here is the pseudocoding for the right approach
Code: |
temp = end - start
if temp > 0 then ,
elapsed = temp
else ,
elapsed = temp + 24 hrs |
|
|
Back to top |
|
|
Rajesh Sampath
New User
Joined: 18 Jun 2008 Posts: 9 Location: Pune
|
|
|
|
Hi enrico-sorichetti
Ya its working fine. But its calculate within the 24 hours.
Im saying,
File sending time is 24/06/2008 at 23:08:47 and acknowledgement received time is 00:14:21 on 26/06/2008.
In this case.
We calculate the date also..
Please correct me. If im wrong
Rajesh Sampath |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
You are not wrong...
If You had said that You had a full timestamp,
I would not have lost time posting an incomplete solution...
use the integer of date to transform the data into an absolute number of days ...
reduce everything to seconds...
time = days*24*60*60 + hours*60*60 + minutes*60 + seconds
elapsed = end - start
use modulus arithmetic to find out the ..
elapsed... days hours minutes seconds
but usually an elapsed is measured in hours minutes seconds ( no days ) |
|
Back to top |
|
|
bijal.awhad
New User
Joined: 19 Mar 2008 Posts: 51 Location: Pune
|
|
|
|
Thanks to all who helped me..
Thanks enrico sorichetti
This is really a helpful forum
Regards
Bijal |
|
Back to top |
|
|
|