Kbase P170265: 4GL/ABL: How to convert Progress DATE and TIME value to UNIX and JMS (Java Message Service) TimeStam
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  7/23/2010 |
|
Status: Unverified
GOAL:
4GL/ABL: How to convert OpenEdge DATETIME values to UNIX and JMS (Java Message Service) TimeStamp values?
GOAL:
How to convert UNIX and JMS (Java Message Service) TimeStamp values to OpenEdge DATETIME values ?
GOAL:
How is the UNIX or POSIX time defined?
GOAL:
How is the JMS TimeStamp defined?
FACT(s) (Environment):
All Supported Operating Systems
OpenEdge 10.x
OpenEdge Category: Language (4GL/ABL)
FIX:
The UNIX, or POSIX time is defined as the number of seconds elapsed since midnight Coordinated Universal Time (UTC) of January 1, 1970, not counting leap seconds. The JMS (Java Message Service) TimeStamp is defined as the number of milliseconds since midnight Coordinated Universal Time (UTC) of January 1, 1970. The following procedure demonstrates how to convert the UNIX time values and the JMS TimeStamp values to the 4GL/ABL DATETIME values and vice-versa:
/*
The "epoch" is a reference point in time which marks the beginning of an era.
In the Progress 4GL, the epoch is midnight, January 1, -4713 and time is measured in units of milliseconds (DATETIME and DATETIME-TZ datatypes) or days (DATE data type) from the epoch.
In UNIX systems, the epoch is midnight January 1, 1970 and time is measured in units of seconds from the epoch.
JMS timestamps the epoch is midnight January 1, 1970 and time is measured in units of milliseconds from the epoch.
In Windows systems, the epoch is Midnight, January 1, 1601 and time is measured in units of centinanoseconds (100 nanosecond intervals) from the epoch.
The six functions below convert between the 4GL's datetime and the clocks used by UNIX, JMS timestamp, and Windows times.
*/
FUNCTION unixTime2DateTime RETURNS DATETIME (INPUT ut AS INT64):
/* Convert UNIX time in seconds to 4GL DATETIME */
RETURN ADD-INTERVAL (DATETIME (1, 1, 1970, 0, 0, 0, 0), ut, "seconds").
END.
FUNCTION dateTime2UnixTime RETURNS INT64 (INPUT dt AS DATETIME):
/* Convert 4GL DATETIME to UNIX time in seconds */
RETURN INTERVAL (dt, DATETIME (1, 1, 1970, 0, 0, 0, 0), "seconds").
END.
FUNCTION JMStime2DateTime RETURNS DATETIME (INPUT jt AS INT64):
/* Convert JMS timestamp in milliseconds to 4GL DATETIME */
RETURN ADD-INTERVAL (DATETIME (1, 1, 1970, 0, 0, 0, 0), jt, "milliseconds").
END.
FUNCTION dateTime2JMStime RETURNS INT64 (INPUT dt AS DATETIME):
/* Convert 4GL DATETIME to JMS timestamp in milliseconds */
RETURN dt - DATETIME (1, 1, 1970, 0, 0, 0, 0).
END.
FUNCTION winTime2DateTime RETURNS DATETIME (INPUT wt AS INT64):
/* Convert Windows time in centinanoseconds to 4GL DATETIME */
wt = wt / 10000.
RETURN ADD-INTERVAL (DATETIME (1, 1, 1601, 0, 0, 0, 0), wt, "milliseconds").
END.
FUNCTION dateTime2WinTime RETURNS INT64 (INPUT dt AS DATETIME):
/* Convert 4GL DATETIME to Windows time in centinanoseconds */
RETURN (INTERVAL (dt, DATETIME (1, 1, 1601, 0, 0, 0, 0), "milliseconds") * 10000).
END.
/* tests - Uses april 29 2010 14:33:22.000 UTC as reference time */
MESSAGE unixTime2DateTime (1272551602)
VIEW-AS ALERT-BOX INFO BUTTONS OK.
MESSAGE dateTime2UnixTime (DATETIME (4, 29, 2010, 14, 33, 22, 0))
VIEW-AS ALERT-BOX INFO BUTTONS OK.
MESSAGE JMStime2DateTime (1272551602000)
VIEW-AS ALERT-BOX INFO BUTTONS OK.
MESSAGE dateTime2JMStime (DATETIME (4, 29, 2010, 14, 33, 22, 0))
VIEW-AS ALERT-BOX INFO BUTTONS OK.
MESSAGE winTime2DateTime (129170252020000000)
VIEW-AS ALERT-BOX INFO BUTTONS O.K.
MESSAGE dateTime2WinTime (DATETIME (4, 29, 2010, 14, 33, 22, 0))
VIEW-AS ALERT-BOX INFO BUTTONS OK..