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:
- H BNDDIR('QC2LE') OPTION(*SRCSTMT)
- H DFTACTGRP(*NO)
-
- D currepoch PR 10I 0 extproc('currEpoch')
- D local_or_gmt 1 Value Options(*NoPass)
-
- D timedate S 26
- D epoch S 10I 0
-
- /Free
- timedate = %Char(%Timestamp()) ;
- epoch = currepoch() ; // Returns GMT seconds since epoch
- timedate = %Char(%Timestamp()) ;
- epoch = currepoch('L') ; // Returns local seconds since epoch
- timedate = %Char(%Timestamp()) ;
- epoch = currepoch('G') ; // Returns GMT seconds since epoch
- *INLR = *On ;
- /End-free
-
-
- P currEpoch B Export
- D currEpoch PI 10I 0
- D local_or_gmt 1 Value Options(*NoPass)
-
-
- D time PR ExtProc('time') Like(time_t)
- D p_time_t Like(time_t)
-
-
- D gettimeofday PR 10I 0 ExtProc('gettimeofday')
- D p_time_t Like(timeval)
- D nullPointer * Value
-
-
- D time_t DS Based(proto_only) Qualified
- D time_t_num 10I 0
-
-
- D timeval DS Based(proto_only) Qualified
- D tv_sec LikeDS(time_t)
- D microseconds 10I 0
-
-
- D curr_time DS LikeDS(time_t)
- D tv DS LikeDS(timeval)
- D gmtTime S N Inz(*On)
-
- /Free
-
- If %Parms >= 1 and local_or_gmt = 'L' ;
- gmtTime = *Off ;
- EndIF ;
-
- If gmtTime ;
- getTimeOfDay(tv: *Null) ;
- curr_time = tv.tv_sec ;
- Else ;
- time(curr_time) ;
- EndIF ;
- Return curr_time.time_t_num ;
-
- /End-free
-
- P currEpoch E
-
|
|
|