Kbase P170433: 4GL/ABL: How to convert Progress DATE and time value to UNIX Time using Progress 9.x?
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  7/30/2010 |
|
Status: Unverified
GOAL:
4GL/ABL: How to convert a Progress DATE and seconds since midnight TIME pair to UNIX INTEGER TIME using Progress 9.x?
GOAL:
How to convert a UNIX INTEGER TIME value to a Progress DATE and seconds since midnight TIME pair using Progress 9.x?
GOAL:
How to convert a UNIX Time INTEGER value to Progress 9.x DATE and TIME string?
FACT(s) (Environment):
All Supported Operating Systems
Progress 9.x
OpenEdge 10.x
FIX:
The following procedure demonstrates how to convert an INTEGER UNIX TIME value to a Progress 9.x DATE and TIME string. It also demonstrates how to convert a Progress 9.x DATE and seconds since midnight TIME pair to UNIX TIME INTEGER value. Notice that this code runs fine under OpenEdge clients:
FUNCTION UnixTime2V9DateTime RETURNS DATE (INPUT iUnixTime AS INTEGER, OUTPUT iSeconds AS INTEGER) FORWARD.
FUNCTION V9DateTime2UnixTime RETURNS INTEGER (INPUT dProgressDate AS DATE, INPUT iSeconds AS INTEGER) FORWARD.
DEFINE VARIABLE iSeconds AS INTEGER NO-UNDO.
/* Tests use April 29, 2010 14:33:22 UTC as reference time */
MESSAGE
"Date:~t" UnixTime2V9DateTime(1272551602, iSeconds) "~n"
"Seconds:~t" iSeconds "~n"
"Time:~t"STRING(iSeconds, "HH:MM:SS")
VIEW-AS ALERT-BOX INFO BUTTONS OK TITLE "UNIX INTEGER time 1272551602 converted to Progress Date and Seconds Since Midnight".
MESSAGE
"UnixTime as number of seconds:~t" V9DateTime2UnixTime(4/29/2010, 52402)
VIEW-AS ALERT-BOX INFO BUTTONS OK TITLE "PROGRESS Date 04/29/2010 and 52402 Seconds Since Midnight (14:33:22) converted to UNIX INTEGER Time" .
FUNCTION UnixTime2V9DateTime RETURNS DATE (INPUT iUnixTime AS INTEGER, OUTPUT iSeconds AS INTEGER):
/* Convert UNIX time in seconds to 4GL DATE and INTEGER seconds since midnight */
DEFINE VARIABLE iDays AS INTEGER NO-UNDO.
ASSIGN
iDays = (iUnixTime - 43200) / 86400
iSeconds = iUnixTime - (iDays * 86400).
RETURN (date (1, 1, 1970) + iDays).
END FUNCTION.
FUNCTION V9DateTime2UnixTime RETURNS INTEGER (INPUT dProgressDate AS DATE, INPUT iSeconds AS INTEGER):
/* Convert Progress 4GL DATE and INTEGER seconds since midnight to UNIX time in seconds */
RETURN ((dProgressDate - date (1, 1, 1970) ) * 86400) + iSeconds.
END FUNCTION.