Question
· Jul 5, 2022

Convert UTC to Specific time zone, Objectscript only

Hi,

I am in a situation where my container is on UTC time (as is the host). But I need to send a datetime to a machine in a specific time zone. Various languages have constructs for doing that, sometimes you need a library

C#: var today = TimeZoneInfo. ConvertTimeFromUtc(timeUtc, easternZone);

python has the pytz library.

import pytz
import datetime
now_utc = datetime.datetime.utcnow()
tz = pytz.timezone('Asia/Kuala_Lumpur')
now_kl = now_utc.replace(tzinfo=pytz.utc).astimezone(tz)

 

We prefer a solution which is ObjectScript only. Because time-zones/daylight saving can change, we would have to import/update the timezones-database at specific times, but during normal operation it should be fairly static code. Is there is solution which is ObjectScript only (and no calling an external service which does the job)?

Regards,

Marcel

Product version: IRIS 2022.1
Discussion (3)1
Log in or sign up to continue

Hi @Marcel den Ouden 

I did something similar a few years back for an ISC internal project.
I required 2 tables to achieve this
- mapping of the location to timezone code  (geographic coordinates are often misleading, STATIC)
- rules and offset from UTC (daylight Saving Y/N, the window when to apply,...) might be flexible
- $ZTZ is your friend and the Docs are really excellent also for special cases

A further complication is mobile use.
example:
- You go to Summit in Seattle. (UTC-7)
- you need to arrange a concall with a customer in Amsterdam (UTC+2) (CEST!)
- and meeting in Nov. (UTC+1)  back to normal time
- And you need to know the time zone used by your notebook (local or home or other?)

For the notebook, I used some JavaScript as the app was written in ZEN (10 yrs.back)
and it was mine and I could control it.
see more in my Article Global Time Management


 

Thanks @Robert Cemper

Since my specific case is for the EU, I think the simplest solution is to use $ZTZ to correct for basic time zone. The rules for summertime are always the same in this area (until they change it, the discussion flares up two times a year). I already found some pseudo-code for that. If summertime, subtract another 60 minutes from $ZTZ. Not as generic as I wanted, but good enough for my case.