midrange.com code scratchpad
Name:
Current number of seconds since Unix epoch - Lovelady
Scriptlanguage:
Plain Text
Tabwidth:
4
Date:
11/22/2011 12:40:54 pm
IP:
Logged
Description:
Returns the number of seconds since 00:00:00 January 1, 1970 in GMT or Local time.

The currEpoch procedure is probably best used as a procedure, and is a part of this program only for demonstration / testability purposes.

Dennis Lovelady
22-Nov-2011 (1321965439 GMT) :)
Code:
  1.      H BNDDIR('QC2LE') OPTION(*SRCSTMT)                               
  2.      H DFTACTGRP(*NO)                                                 
  3.                                                                       
  4.      D currepoch       PR            10I 0 extproc('currEpoch')       
  5.      D  local_or_gmt                  1    Value Options(*NoPass)     
  6.                                                                       
  7.      D timedate        S             26                               
  8.      D epoch           S             10I 0                            
  9.                                                                       
  10.       /Free                                                           
  11.        timedate = %Char(%Timestamp()) ;                               
  12.        epoch = currepoch() ;      // Returns GMT seconds since epoch  
  13.        timedate = %Char(%Timestamp()) ;                               
  14.        epoch = currepoch('L') ;   // Returns local seconds since epoch
  15.        timedate = %Char(%Timestamp()) ;                               
  16.        epoch = currepoch('G') ;   // Returns GMT seconds since epoch  
  17.        *INLR = *On ;                                                  
  18.       /End-free                                                       
  19.                                                                       
  20.                                                                       
  21.      P currEpoch       B                   Export                     
  22.      D currEpoch       PI            10I 0                            
  23.      D  local_or_gmt                  1    Value Options(*NoPass)     
  24.                                                                         
  25.                                                                         
  26.      D time            PR                  ExtProc('time') Like(time_t) 
  27.      D  p_time_t                           Like(time_t)                 
  28.                                                                         
  29.                                                                         
  30.      D gettimeofday    PR            10I 0 ExtProc('gettimeofday')      
  31.      D  p_time_t                           Like(timeval)                
  32.      D  nullPointer                    *   Value                        
  33.                                                                         
  34.                                                                         
  35.      D time_t          DS                  Based(proto_only) Qualified  
  36.      D  time_t_num                   10I 0                              
  37.                                                                         
  38.                                                                         
  39.      D timeval         DS                  Based(proto_only) Qualified  
  40.      D  tv_sec                             LikeDS(time_t)               
  41.      D  microseconds                 10I 0                              
  42.                                                                         
  43.                                                                         
  44.      D curr_time       DS                  LikeDS(time_t)               
  45.      D tv              DS                  LikeDS(timeval)              
  46.      D gmtTime         S               N   Inz(*On)                     
  47.                                               
  48.       /Free                                   
  49.                                               
  50.        If %Parms >= 1 and local_or_gmt = 'L' ;
  51.           gmtTime = *Off ;                    
  52.        EndIF ;                                
  53.                                               
  54.        If gmtTime ;                           
  55.           getTimeOfDay(tv: *Null) ;           
  56.           curr_time = tv.tv_sec ;             
  57.        Else ;                                 
  58.           time(curr_time) ;                   
  59.        EndIF ;                                
  60.        Return curr_time.time_t_num ;          
  61.                                               
  62.       /End-free                               
  63.                                               
  64.      P currEpoch       E                      
  65.  
© 2004-2019 by midrange.com generated in 0.006s valid xhtml & css