Best Practice for handling timezone offsets in DTL
Hi all,
My team is exploring options for handling timezone offsets in DTL and we’re wondering if there are any built-in methods available — ideally low-code or no-code solutions. Specifically, we're looking for a way to adjust timestamps based on the date and whether Daylight Saving Time (DST) is in effect.
For example, if an HL7 message has an MSH-7 value of 20250518144529, it should be converted to 20250518144529-0500 (Central Daylight Time), but if the timestamp were 20250218144529, it should be 20250218144529-0600 (Central Standard Time).
We’re fairly new to InterSystems and want to make sure we’re not reinventing the wheel if there’s already a best practice or supported feature for this.
Thanks in advance for any guidance!
Comments
I tend to use $SYSTEM.SQL.Functions.DATEADD()
You can use this to add seconds, minutes, hours, days, etc. to date. The date/time should be ODBC e.g "2025-05-21T14:52:47.986"
There may be other ways, but this is how I do it to deal with UTC offsets.
This comment shows a quick way to convert to ODBC
https://community.intersystems.com/post/convert-numeric-expression20201…
You may have to tweak a little.
USER>w $tr("abcd-ef-gh ij:kl:00","abcdefghijkl",20250518144529)
2025-05-18 14:45:00
USER>s time=$tr("abcd-ef-gh ij:kl:00","abcdefghijkl",20250518144529)
USER>w time
2025-05-18 14:45:00
USER>s time=$SYSTEM.SQL.Functions.DATEADD("hh",-6,time)
USER>w time
2025-05-18 08:45:00
I am bad at full thoughts evidently: do read on timezones and DST though so you don't hit any traps - https://docs.intersystems.com/iris20251/csp/docbook/DocBook.UI.Page.cls…
It appears in your example you need a better way to determine if you are in DST or standard. You can't just go off of month and you also might be dealing with a region that doesn't acknowledge DST.
Ya we know there is a lot of edge cases. We tried to handle them in our old system Cloverleaf with Tcl/Tk code, and before moving to InterSystems using Objectscript we wanted to do research on what way was best. Thank you for feedback.
Our team was unable to find any built-in functions for handling timezones/offsets and had to develop our own library that uses the built-in timezone database installed on our Redhat servers.
Check out this article: Time Zones and Offsets and ObjectScript, Oh My! | InterSystems Developer
Here's the related library: tz---ObjectScript-Time-Zone-Conversion-Library
Let me know if you have any questions/problems with this library.