Question
· Dec 10, 2023

Converting $H to UTC for a timezone that is not local (Object Script)

Working on a project where we have a web browser that we have to determine a pickup date/time for a pharmacy in a different time zones.

We store the different time zones with their Daylight and Standard offsets.

We have a object script method that figures out the the pickup date/time for a particular pharmacy in their local time zone but the data is being returned in the $H format.   

We now need to return it in a UTC format.  I see different methods but don't see a method that will change the $H into a UTC for a different timezone otherwise than the local timezone.  

I know I can figure a way around it but I was wondering if anyone has found that Intersystems has a method that will do it for you?

Thanks,

Kris Roberts

Product version: IRIS 2023.1
$ZV: IRIS for Windows (x86-64) 2023.1 (Build 229U) Fri Apr 14 2023 17:17:41 EDT
Discussion (16)2
Log in or sign up to continue

One more question Rich,

I tried reading the %Libraray.PosixTime class information.  I thought that the PosixTime was the days in seconds since Jan 1, 1970 but I think I am missing something.  The PosixTime is in seconds so I was thinking I could....

  • take a time stamp and convert it to a PosixTime
  • an then for an Timezone offset (for example America/New_York would be -05:00) convert it to seconds  -1800
  • add the -1800 to the PosixTime
  • an then convert PosixTime to time stamp - shouldn't the time stamp show a lot more of a difference?  
  • and then convert the PosixTime back to a time stamp and shouldn't it show the timestamp a lot less  than 18 seconds? see below 

Starting a cold or something so my mind might not be thinking clearly.

Thanks

Robert, it sounds strange, but... Setting the Time Zone

You can use $ZTIMEZONE to set the time zone used by the current InterSystems IRIS process. Setting $ZTIMEZONE does not change the default InterSystems IRIS time zone or your computer’s time zone setting.

IMHO, $ztimezone setting is dangerous not for its system-wide effect (which it hasn't) but mostly due to its exclusions and anomalies, despite they are accurately listed in docs.

You can change the Timezone system variable

//  for example EST (Eastern Standard Time, 5 hours behind UTC)
    set $ztz = 300
//  you can even consider daylight saving
//  for example CET (Central European Time, 1 hour ahead of UTC)
#define DSTOFFSET	-60
#; -60=CET, 300=EST
#define LOCALZONE   -60
    set $ztz = $$$LOCALZONE+$s($system.Util.IsDST():$$$DSTOFFSET,1:0)
    

Setting $ZTZ affects the current job only (the job, which sets $ztz), so there is no danger for other processes.

Shouldn't be a problem, $ZTZ isn't the only thing you can change.

Whatever value or setting you change, $namespace, $zeof, $horolog, etc. you have to consider a simple rule, if you change things (which can be used by subsequent routines, methods, etc.) for your own use, then after using them, you have to restore them to their original value. That's all.

YouRESTorWHATEVERmethod()
{
  set oldZTZ=$ztz
  set $ztz=<your preferred value>
  ...
  set $ztz=oldZTZ
  return
}