REXX Convert Stck Date to/from readable                         goto homepage

Stck Datum in “lesbares” Format umstellen oder umgekehrt – der Aufruf kann sowohl per Programm (REXX) als auch als Line-Command erfolgen

 

/* REXX YSTCK    Copyright YCOS Yves Colliard Software 2009-09 V1.0   */       
/*--------------------------------------------------------------------*/       
/* YSTCK     - Convert to / from STCK                                 */       
/*--------------------------------------------------------------------*/       
/* REXX Tool                                                          */       
/**********************************************************************/       
/*  V1.0 - 02.07.2009 - first release                                 */       
/*--------------------------------------------------------------------*/       
/* Syntax:                                                            */       
/* YSTCK toSTCK/toTOD yyyydddhhmmss<.mmmmmm>/stck <INT>               */       
/* parms                                                              */       
/*   toSTCK yyyydddhhmmss<.mmmmmm>  z.B. 2009093084530                */       
/*                                  z.B. 2009093084530.5              */        
/*                                  z.B. 2009093084530.999999         */       
/*   toTOD  stck                    z.B. C3FB2DAE99E80000             */       
/*                 Int = blank   -> say the result                    */       
/*                 Int = "INT"   -> return  result                    */       
/*                                  rc"/"date or msg                  */       
/*========================================
============================*/       
  /* */                                                                         
/* TRACE ?R  */                                                                
  /* einschalten des interaktiven Trace Modus */                               
  /* */                                                                         
arg      Form Zeit Int                                                         
select                                                                         
when Form="TOSTCK" then do                                                      
  if   DataType(Zeit) <> "NUM" then do                                         
       call retour "4/Time Format Error - not Num" Zeit                        
  end                                                                           
  if       Length(Zeit) < 13      then do                                      
       call retour "8/Time Format Error - less than 13 Chars" Zeit             
  end                                                                           
  if       Length(Zeit) > 20      then do                                      
       call retour "8/Time Format Error - more than 20 Chars" Zeit             
  end                                                                          
  parse    var Zeit ZeitD +7 ZeitH +2 ZeitM +2 ZeitS +2 Deci                   
  select                                                                       
  when Deci="" then do                                                         
    Deci = 0                                                                    
  end                                                                          
  when left(Deci,1)<>"." then do                                               
    call retour "8/Time Format Error - Decimal point" Deci                     
  end                                                                          
  when datatype(substr(Deci,2))<>"NUM" then do                                 
    call retour "8/Time Format Error - Decimal not NUM" Deci                   
  end                                                                          
  otherwise                                                                    
    Deci = left(substr(Deci,2)"000000",6)                                       
  end                                                                          
  signal   on Syntax Name Return12                                             
  SDate    = left(ZeitD,2)""substr(Date("S",SubStr(ZeitD,3),"J"),3)            
  JDate    = Date("B",SDate,"S")                                               
  if       ZeitH > 23 then do                                                  
       call retour "8/Time Format Error - HH > 23 -" ZeitH                     
  end                                                                          
  if       ZeitM > 59 then do                                                  
       call retour "8/Time Format Error - MM > 59 -" ZeitM                     
  end                                                                           
  if       ZeitS > 59 then do                                                  
       call retour "8/Time Format Error - SS > 59 -" ZeitS                     
  end                                                                           
  Numeric  Digits 64                                                           
  D        = JDate-Date("B","19000101","S")                                    
  H        = (D * 24) + ZeitH                                                   
  M        = (H * 60) + ZeitM                                                  
  S        = (M * 60) + ZeitS                                                  
  TS       = S  * 1000000                                                       
  TS       = TS + Deci                                                         
  call retour "0/"right("0000000000000"D2X(TS),13)"000"                        
end                                                                             
when Form="TOTOD" then do                                                      
/* */                                                                          
  Numeric Digits 20           /* increase significant digits to 20 */           
  signal   on Syntax Name Return12                                             
  Secs   = X2D(SubStr(Zeit,1,13))     /* Ignore last 1.5 bytes     */          
  msec   = right("0000000"secs//1000000,6) /* micro secs     */                
  times  = secs%1000000                                                        
  sec    = times//60                         /* seconds      */                
  timem  = times%60                                                            
  min    = timem//60                         /* minutes      */                
  timeh  = timem%60                                                            
  hrs    = timeh//24                         /* hours        */                
  timed  = (timeh%24)+date("B","19000101","S") /* days since 1900 */           
  cent   = left(date("S",timed,"B"),2)                                         
  call retour "0/"insert(cent,date("E",timed,"B"),6),                          
       y(Hrs,2)":"y(Min,2)":"y(sec,2)"."y(msec,6)                              
end                                                                            
otherwise                                                                      
  call retour "8/Parameter Error: toSTCK / toTOD"                               
end                                                                            
exit                                                                           
/* */                                                                           
Return12:                                                                      
select                                                                         
when Form="TOSTCK" then do                                                     
     call retour "12/Syntax Error in toSTCK - Parms:" form zeit                
end                                                                            
when Form="TOTOD" then do                                                      
     call retour "12/Syntax Error in toTOD - Parms:" form zeit                 
end                                                                            
otherwise                                                                      
  call retour "12/Syntax Error"                                                 
end                                                                            
/* */                                                                          
retour:                                                                         
if Int="INT" then do                                                           
  exit arg(1)                                                                  
end                                                                             
else do                                                                        
  parse value arg(1) with retc "/" txt                                         
  say txt                                                                       
  exit retc                                                                    
end                                                                            
/* */                                                                          
y: procedure                                                                   
return right(copies("0",arg(2))""arg(1),arg(2))