©
serviceprofessionalgmbh
Natürlich sind die Variationen grenzenlos. Wir haben hier folgende Funktionalitäten realisiert:
/* REXX
Benutzung siehe Programmende
*/
arg FKT,PARM1,PARM2,DUMMY
select
when FKT = "T2S" then ERG = time_to_sec(PARM1)
when FKT = "S2T" then ERG = sec_to_time(PARM1)
when FKT = "TD" then ERG = time_diff("T",PARM1,PARM2)
when FKT = "SD" then ERG = time_diff("S",PARM1,PARM2)
otherwise ERG = "ERROR Incorect CALL to routine"
end
return ERG
/* SUBROUTINES **************************************************/
sec_to_time: procedure
SEC = arg(1)
if datatype(SEC,"W") = 0 then return "ERROR nicht SEC numerisch"
do I = 0 while SEC > 86399
SEC = SEC - 86399
end
STD = SEC % 3600
SEC = SEC // 3600
MIN = SEC % 60
SEC = SEC // 60
ERG = "OK" right(STD,2,0)":"right(MIN,2,0)":"right(SEC,2,0)
if I > 0 then ERG = ERG "+"i
return ERG
time_diff: procedure
arg TYPE,TIME1,TIME2
if time_error(TIME1) then return "ERROR Zeit1 falsch (hh:mm:ss)"
if time_error(TIME2) then return "ERROR Zeit2 falsch (hh:mm:ss)"
SEC1 = word(time_to_sec(TIME1),2)
SEC2 = word(time_to_sec(TIME2),2)
if SEC2 < SEC1 then SEC2 = SEC2 + 86400
if TYPE = "T" then ERG = word(sec_to_time(SEC2-SEC1),2)
else ERG = SEC2-SEC1
return "OK" ERG
time_to_sec: procedure
if time_error(arg(1)) then return "ERROR Zeitformat falsch (hh:mm:ss)"
parse value arg(1) with STD ":" MIN ":" SEC
return "OK" ((STD * 60 + MIN) * 60) + SEC
time_error: procedure
parse value arg(1) with STD ":" MIN ":" SEC
ERROR = 1
select
when datatype(STD !! MIN !! SEC,"W") = 0 then nop
when STD > 23 ! MIN > 59 ! SEC > 59 then nop
otherwise ERROR = 0
end
return ERROR
/* USAGE ************************************************************/
>>----- zeit(fkt,--parm1--+--------+------><
| |
+-,parm2-+
fkt parm1 parm2 result Bedeutung
------ -------- ---------- ---------------- --------------------
T2S hh:mm:ss kein OK sssss Anzahl Sekunden
S2T sssss kein OK hh.mm.ss [+n] evtl. +tage
TD hh:mm:ss hh:mm:ss OK hh:mm:ss Differenz im Zeitformat
SD hh:mm:ss hh:mm:ss OK sssss Differenz in Sekunden
Beispiel:
parse value ZEIT("TD","12:05:00","10:35:28") with ERG INFO
if ERG = "OK" then do
say "Zeitdifferenz:" INFO >> 22:30:28
...
end
else do
say ERG ">>" INFO
...
end
zurück zu Datum & Zeit