[Progress Communities] [Progress OpenEdge ABL] Forum Post: RE: DATETIME-TZ function handling DST

Status
Not open for further replies.
A

Akshay Guleria

Guest
Thanks Robin Brown for your reply. I ended up doing something similar. It's direct call to OS in order to use the tzdb (Olson db). The usage of this in our case not extensive (and only limited to unix/linux os) so it is not much of an overkill for us. This method can be used to convert any timezone timestamp with correct timezone offset, even when the stored UTC timestamp was in a different timezone due to DST rules. METHOD PUBLIC STATIC DATETIME-TZ ConvertIsoToLocal(icISOTimeStamp AS CHAR, icTZCanonicalId AS CHAR): /* Convert ISO format (YYYY-MM-DDTHH:MM:SS+Z) timestamps to desired timezone's timestamp. input tz should be a valid canonical id */ DEF VAR lcDateFormat AS CHAR NO-UNDO. DEF VAR lcResult AS CHAR NO-UNDO. DEF VAR lcCommand AS CHAR NO-UNDO. DEF VAR lcArguments AS CHAR NO-UNDO. DEF VAR lcTSFormat AS CHAR NO-UNDO. lcDateFormat = SESSION:DATE-FORMAT. SESSION:DATE-FORMAT = "ymd". /* if OS is not unix/linux then this method cannot evaluate. hence return original timestamp */ IF OPSYS <> "UNIX" THEN RETURN DATETIME-TZ(icISOTimeStamp). /* prepare the command and format of timestamp */ lcTSFormat = "+'%Y-%m-%d %H:%M:%S.%3N%:z'". lcCommand = SUBST("TZ='&1' date", icTZCanonicalId). lcArguments = SUBST("-d '&1' &2", icISOTimeStamp, lcTSFormat). /* call the os date function and capture the resulting timestamp */ INPUT THROUGH VALUE(lcCommand) VALUE(lcArguments) NO-ECHO. IMPORT UNFORMATTED lcResult. INPUT CLOSE. RETURN DATETIME-TZ(lcResult). FINALLY: SESSION:DATE-FORMAT = lcDateFormat. END FINALLY. END METHOD.

Continue reading...
 
Status
Not open for further replies.
Top