Focal Point
Challenge (time conversion, dialog mgr) [CODE]

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/704101162

October 07, 2009, 10:34 PM
j.gross
Challenge (time conversion, dialog mgr) [CODE]
Given a Dialog Manager variable &TIME containing the time of day (in 24-hour clock format, 'hh:mm:ss')

Convert the time to 'Seconds Elapsed Since Midnight', in two lines of Dialog Manager code not exceeding 80 characters in length.

This message has been edited. Last edited by: j.gross,


- Jack Gross
WF through 8.1.05
October 07, 2009, 11:09 PM
Waz
I'm sure there is a better way, but ...
-SET &SECS=ATODBL(EDIT(&TIME,'99'),2,'D2')*3600+
-ATODBL(EDIT(&TIME,'$$$99'),2,'D2')*60+ATODBL(EDIT(&TIME,'$$$$$$99'),2,'D2');



Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

October 08, 2009, 02:07 AM
Tony A
Not necessarily better but this is a method using the current time (line length is 72 chars) -

-SET &Secs=HDIFF(HGETC(8,'HYYMDS'),HMIDNT(HGETC(8,'HYYMDS'),8,'HYYMDS'),
-    'SECOND','I9');

T



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10 
October 08, 2009, 03:02 AM
GamP
My attempt to solve this challenge:
-SET &SEC = HDIFF(HINPUT(20, '2009/01/01 &TIME.EVAL', 8, 'HYYMDS'),
- HINPUT(20, '2009/01/01 00:00:00', 8, 'HYYMDS'), 'SECOND', 'I7');



GamP

- Using AS 8.2.01 on Windows 10 - IE11.
in Focus since 1988
October 08, 2009, 05:45 AM
j.gross
Here's what I had in mind:

-SET &TIME=HHMMSS('A8');

-SET &ELAPSED=EDIT(&TIME,'99*3600 + $99*60 + $99');
-SET &ELAPSED=&ELAPSED.EVAL;


which gives, successively,
 &TIME         = 05.42.43
 &ELAPSED      = 05*3600 + 42*60 + 43
 &ELAPSED      = 20563



- Jack Gross
WF through 8.1.05
October 08, 2009, 08:48 AM
GamP
Were you very much disappointed with the results we gave you?
Did we fail some kind of test or loose points or maybe even the opposite? Confused

Anyway, your solution is quite elegant and it goes to show that there is more than one way to 'defur a feline'. Wink


GamP

- Using AS 8.2.01 on Windows 10 - IE11.
in Focus since 1988
October 08, 2009, 09:16 AM
Prarie
quote:
'defur a feline'



I love it!...so much more humane than the usual saying.
October 08, 2009, 09:54 AM
susannah
Good One gamp.
i think this was just the brain teaser of the day... what a fun idea...




In Focus since 1979///7706m/5 ;wintel 2008/64;OAM security; Oracle db, ///MRE/BID
October 08, 2009, 10:54 AM
j.gross
It all started when I reported to this assignment, poked around in the common code module for calculating run duration, and said to myself -- good idea, but there has to be a more succinct way of implementing the calculations...

But it does go to show that .EVAl is more than a necessary nuisance.


Anyway, here's how I would do it (wrapped in an illustrative test bed):

-REPEAT TEST FOR &J FROM 1 TO 3 ;
-*
-*--------------------------------------
** prolog: 
-SET &time1=HHMMSS('A8');
-*--------------------------------------

-TEST: SET &time1=DECODE &J (2 '01:01:01' 3 '22.58.59' ELSE '&time1.EVAL');
-*
** body
SLEEP 2
-*
-*--------------------------------------
** epilog: 
-RUN 
-SET &time2=HHMMSS('A8');
-* calculate difference  between &time1 and &time2 in seconds.
-* [3600 sec.=an hour, 86400 sec.=a day]
-SET &sec1=EDIT(&time1,'(99*3600)+$(99*60)+$(99)');
-SET &sec1=&sec1.EVAL;
-SET &sec2=EDIT(&time2,'(99*3600)+$(99*60)+$(99)');
-SET &sec2=&sec2.EVAL;
-* calculate elapsed seconds. 
-* adjust if negative (as when job overlaps midnight)
-SET &sec =IMOD((&sec2-&sec1)+86400,86400,'I5');
-* format elapsed time for display.
-SET &elapsed=1000000 +10000*INT(&sec/3600) +100*IMOD(INT(&sec/60),60,'I2L') +IMOD(&sec,60,'I2L');
-SET &elapsed=EDIT(&elapsed, '$99:99:99');
-TYPE
-TYPE <*> Start=&time1, End=&time2, Elapsed=&elapsed (&sec seconds) <*>
-TYPE
-*--------------------------------------

-TEST


Output:
 <*> Start=10.53.02, End=10.53.04, Elapsed=00:00:02 (2 seconds) <*>
 <*> Start=01:01:01, End=10.53.06, Elapsed=09:52:05 (35525 seconds) <*>
 <*> Start=22.58.59, End=10.53.08, Elapsed=11:54:09 (42849 seconds) <*>



- Jack Gross
WF through 8.1.05