Calculate Elapsed time

77 views
Skip to first unread message

IZZI ZMAN

unread,
Mar 30, 2024, 12:55:18 PMMar 30
to mvd...@googlegroups.com
Been away from UniVerse for awhile so I'm kinda stumped, should be
simple but haven't found the right conversion.
It looks like the dates in the logfile are typical of the TIMEDATE()
function but I  can't convert...SO, let's ask the experts !
Trying to ICONV somehow but nothing seems to work other than to error
out for me.

I'm trying to calculate Elapsed Time

UniVerse 10.1 I'm parsing a Log file that has dates in the format of:

18:38:43 21 MAR 2024
00:10:32 22 MAR 2024

Appreciate any help !
Izzi

Joe Goldthwaite

unread,
Mar 30, 2024, 1:04:37 PMMar 30
to mvd...@googlegroups.com
I don't know of a standard way to convert a timedate together. It's usually split apart. Here's an example that uses the field statement to parse out the parts. There are lots of ways to do it. I don't know if this is the best or not.

* SAMPLE DATE
DT = "18:38:43 21 MAR 2024"

* GET THE TIME PART
TIMEPART = FIELD(DT,' ', 1)
PRINT TIMEPART

* GET THE DATE PART
DATEPART = FIELD(DT,' ', 2, 4)
PRINT DATEPART

* WE CAN ICONV DATEPART AND TIMEPART BUT WE CAN ALSO DO IT ALL TOGETHER
IDATE = ICONV(FIELD(DT,' ', 2, 4),'D')
ITIME = ICONV(FIELD(DT,' ', 1, 1),'MT')

* OCONV THE RESULT
PRINT OCONV(IDATE,'D2-')
PRINT OCONV(ITIME,'MTHS')

Joe Goldthwaite

IZZI ZMAN

unread,
Mar 30, 2024, 1:15:25 PMMar 30
to mvd...@googlegroups.com
Joe,

Damn ! I know this and should have known this!

I was so consumed with the complete DT string that I didn't think of the
trusty FIELD statement !

Thanks for keeping me sane !
Izzi

Joe Goldthwaite

unread,
Mar 30, 2024, 1:25:57 PMMar 30
to mvd...@googlegroups.com
You're welcome!

Calculating the elapsed time is a little more involved.

START.DT = "18:38:43 21 MAR 2024"
END.DT = "00:10:32 22 MAR 2024"

* GET THE START AND END TIMES
START.TIME = ICONV(FIELD(START.DT,' ', 1),'MT')
END.TIME = ICONV(FIELD(END.DT,' ', 1),'T')

* GET THE START AND END DATES
START.DATE = ICONV(FIELD(START.DT,' ', 2, 4),'D')
END.DATE = ICONV(FIELD(END.DT,' ', 2, 4),'D')

* CONVERT THEM TO SECONDS
START.SECONDS = (START.DATE * 86400) + START.TIME
END.SECONDS = (END.DATE * 86400) + END.TIME

* CALULATE THE ELAPSED SECONDS
ELAPSED.SECONDS = END.SECONDS - START.SECONDS


PRINT ELAPSED.SECONDS

* YOU CAN VERERT THE ELAPSED SECONDS TO HH:MM:SS TO GET THE INDIVIDUAL ELEMENTS
* IF YOU CHANGE THE START DATE TO 2023 YOU'LL GET REALLY BIG HOURS.
PRINT OCONV(ELAPSED.SECONDS,'MTHS')


Jim Idle

unread,
Mar 30, 2024, 1:37:52 PMMar 30
to mvd...@googlegroups.com
I think this is like an XY question.

Don't use logs to implement observability - you are already seeing why. Calculating things from logs is usually a sign that they are being used for something they should not be.

I don't know why fairly recently the development world thinks that logging is for this and everything else. Logging is for debug and trace in development mode and errors/exceptions in production mode. I think it is the stupid Splunk startup that influenced this. If you just randomly log things, you will not be able to spot things that need attention. Then you will write programs to look for things in the logs... and so on.

Another test is writing logs that are not easily machine parsed. 

If you need metrics and observability, then write an interface to use standard systems such as https://prometheus.io/, which you can then feed into Grafana dashboards. Or if you don't go that far, use a file (but be careful of IO overhead).

Someone should write an open source interface for Prometheus. 

Please don't read this as any kind of attack on you though. Many times we are stuck with what we have and must make the best of it.

Jim



--
You received this message because you are subscribed to
the "Pick and MultiValue Databases" group.
To post, email to: mvd...@googlegroups.com
To unsubscribe, email to: mvdbms+un...@googlegroups.com
For more options, visit http://groups.google.com/group/mvdbms
--- You received this message because you are subscribed to the Google Groups "Pick and MultiValue Databases" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mvdbms+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mvdbms/baaeb0e5-9066-43b7-a864-66c7f88e6431%40gmail.com.

Jay LaBonte

unread,
Mar 30, 2024, 6:26:36 PMMar 30
to mvd...@googlegroups.com
I will have to look for the code, but I wrote a routine that simply converts the date and time string to EPOCH. Then it’s a simple matter from subtracting one from the other. The result in the number of second between the two timestamps. Divide by 86400 to get the number of days. What left is the second on the last day.

I have also found ti easier to store most of my date time stamps in EPOCH.

Regards,
Jay LaBonte
--
You received this message because you are subscribed to the "Pick and MultiValue Databases" group.
To post, email to: mvd...@googlegroups.com To unsubscribe, email to: mvdbms+un...@googlegroups.com
For more options, visit http://groups.google.com/group/mvdbms
---
You received this message because you are subscribed to the Google Groups "Pick and MultiValue Databases" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mvdbms+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mvdbms/CYuY6I2gkAMKWa2GE_WMEx_-jkODrqnE5FSEV6bcILp4XrrlAkU_d7Yi51eFN2UiZniMgxUuQKFBoE_aYnI23WkncSf-V0xDfSLlWLaAsNs%3D%40goldthwaites.com.

IZZI ZMAN

unread,
Mar 30, 2024, 8:42:05 PMMar 30
to mvd...@googlegroups.com
Jay,

That's what I actually envisioned, with all of the MV functions
available. After Joe responded, I did the same thing by peeling off the
time, ICONV using "MT" then subtract.
worked great until you went into the next day !

Thanks All and let me know what you come up with.

Izzi

Wol

unread,
Mar 31, 2024, 8:28:23 AMMar 31
to mvd...@googlegroups.com
On 31/03/2024 00:42, IZZI ZMAN wrote:
> Jay,
>
> That's what I actually envisioned, with all of the MV functions
> available. After Joe responded, I did the same thing by peeling off the
> time, ICONV using "MT" then subtract.
> worked great until you went into the next day !
>
> Thanks All and let me know what you come up with.
>
> Izzi

"Worked great until you went into the next day" ...

That's why Epoch is such a good idea. I'm going to have to think hard
about this problem in the near future, because the system I'm planning
to write for work doesn't start the day at midnight. Our working day
starts with the night shift clocking on about 10pm (if not earlier),
then the AM shift from 5:30AM, the day shift about 7AM, the PM shift
about 2PM, and then finally the last people are supposed to clock off at
midnight (assuming they're not running late - I've clocked off about 2AM
and while uncommon, it's not unusual).

I need to think about (a) how to feed the day into the time-format
function, and (b) how to display the time before 00:00 or after 23:59.
Working in Excel at the moment, it's an absolute nightmare because I
don't know whether I have a date-time (which I can do maths on), or a
time (which will screw up).

Okay, working in OpenQM it'll handle Epoch natively, but it still
doesn't handle times outside the clock day.

Cheers,
Wol

Jay LaBonte

unread,
Mar 31, 2024, 9:32:38 AMMar 31
to mvd...@googlegroups.com
In that case I would adjust the time by the shift and either add or subtract the number of second after midnight from the start and stop times.


Sent from my iPhone

> On Mar 31, 2024, at 8:28 AM, Wol <antl...@youngman.org.uk> wrote:
> --
> You received this message because you are subscribed to
> the "Pick and MultiValue Databases" group.
> To post, email to: mvd...@googlegroups.com
> To unsubscribe, email to: mvdbms+un...@googlegroups.com
> For more options, visit http://groups.google.com/group/mvdbms
> --- You received this message because you are subscribed to the Google Groups "Pick and MultiValue Databases" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to mvdbms+un...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/mvdbms/1a835ac4-bd02-4c4a-bb2b-8c53e2d42af0%40youngman.org.uk.

IZZI ZMAN

unread,
Mar 31, 2024, 11:02:34 AMMar 31
to mvd...@googlegroups.com
Thank you all ! Here's what I'm going with for simplicity. Something that needs to be considered for more important use is that  End Date is not Greater than the Start Date ! And don't knit pick with the 1 second difference at Midnight ! Because it's not a factor in this application.   - izzi

     TST.ELAPSED.TIME

0001       SDT = "18:00:00 21 MAR 2024"

0002       START.HR = FIELD(SDT,':',1)

0003       EDT = "00:10:32 22 MAR 2024"

0004       END.HR = FIELD(EDT,':',1)

0005 *

0006 * Strip Time to Internal

0007 *

0008       STM = ICONV(FIELD(SDT,' ',1,1),'MT')

0009       ETM = ICONV(FIELD(EDT,' ',1,1),'MT')

0010       MIDNIGHT = ICONV("23:59:59",'MT')

0011 *

0012       CRT "Test Start Date : ":SDT

0013       CRT "Test End Date   : ":EDT

0014       CRT

0015       CRT "Start Time Internal :":STM

0016       CRT "End Time Internal : ":ETM

0017       CRT "Midnight : ":MIDNIGHT

0018 *

0019       IF END.HR LT START.HR THEN

0020          ELAPSED.TIME = (MIDNIGHT - STM) + ETM

0021       END ELSE

0022          ELAPSED.TIME = (STM - ETM)

0023       END

0024       CRT

0025       CRT 'Elapsed Time : ':OCONV(ELAPSED.TIME,'MTS')

0026       STOP

0027    END

>

>

Test Start Date : 18:00:00 21 MAR 2024

Test End Date   : 00:10:32 22 MAR 2024

 

Start Time Internal :64800

End Time Internal : 632

Midnight : 86399

 

Elapsed Time : 06:10:31

Richard Wilson

unread,
Mar 31, 2024, 11:25:32 AMMar 31
to mvd...@googlegroups.com
why not just use @DATE & @TIME

then you won't have to worry about parsing or dates in various formats DD-MM-YYYY, MM-DD-YYYY

Wol

unread,
Mar 31, 2024, 5:47:54 PMMar 31
to mvd...@googlegroups.com
On 31/03/2024 14:32, 'Jay LaBonte' via Pick and MultiValue Databases wrote:
> In that case I would adjust the time by the shift and either add or subtract the number of second after midnight from the start and stop times.
>
Which midnight?

We have the concept of "Delivery Day", which starts before midnight
00:00, and can end after midnight 24:00.

I've tried to do those shenanigans in Excel, and its a mess. Okay, not
helped by a lot of legacy crud I've inherited, but conceptually, the
easiest way to handle it is just to accept that time (as in hh:mm) can
be negative or greater than 24.

And crapping about with adjusting time is likely to give you nasty sharp
edges to cut yourself on. I *hope* I've blunted mine, but I wouldn't
bank on it ...

Cheers,
Wol

Joe G

unread,
Mar 31, 2024, 8:25:04 PMMar 31
to Pick and MultiValue Databases
Hi Izzi,

It looks like you're not trying to calculate the difference between to start and end times. it looks like you want the number of days?  What are you actually trying to do with the beginning and ending dates? Give some example beginning and ending dates and what result you're looking to get.

Joe Goldthwaite

Joe G

unread,
Apr 1, 2024, 12:15:29 AMApr 1
to Pick and MultiValue Databases
It looks like I had an error in that last sample I posted.  I had this for END.TIME: "END.TIME = ICONV(FIELD(END.DT,' ', 1),'T')". That "T" should have been "MT" so:

END.TIME = ICONV(FIELD(END.DT,' ', 1),'MT')

I found it when I tried to reverse the start and end times and got some weird results. Once I fixed it, it started working correctly. 
Reply all
Reply to author
Forward
0 new messages