Give us feedback
Register your copy of Developer Studio
Developer Studio Workshop

Using Reg.exe to Offset Time Zones From a Windows-Based System
By John Gray
Information Builders

Time zone awareness is a major problem for most of us living outside the military. Those in the military world work on a single time zone wherever they are, so if you are in the military when its 1:00 AM in Tokyo, its 1:00 AM in New York.

However, the rest of us live in the normal world and because we do not want to get out of bed at some ungodly hour to take a phone call, we rely on the time zone system to keep us coordinated.

A particular issue with this is that computer systems and software need to know the basis of where they are and what different offsets they are working on in order to be able to communicate correctly.

As in Susannah Jones' article, "Zulu Time – How to Read the ReportCaster Schedule File," knowing where you are is of great importance.

Fortunately for us, most computer systems can make the required information available to you, if you know where to look.

Microsoft has 75 named time zone locations; many are duplicates from an actual time perspective because there are only 33 official time zones throughout the world. The reason 75 is listed is partly political and partly due to different starting dates for daylight savings.

The standard zones range from +13 (thirteen hours ahead) and -12 (twelve hours behind) GMT. And with the exception of seven, all are whole hours.

The current list from Microsoft is as follows:

(GMT-12:00) International Date Line West
(GMT-11:00) Midway Island, Samoa
(GMT-10:00) Hawaii
(GMT-09:00) Alaska
(GMT-08:00) Pacific Time (US & Canada); Tijuana
(GMT-07:00) Arizona
(GMT-07:00) Mountain Time (US & Canada)
(GMT-07:00) Chihuahua, La Paz, Mazatlan
(GMT-06:00) Central America
(GMT-06:00) Guadalajara, Mexico City, Monterrey
(GMT-06:00) Saskatchewan
(GMT-06:00) Central Time (US & Canada)
(GMT-05:00) Bogota, Lima, Quito
(GMT-05:00) Eastern Time (US & Canada)
(GMT-05:00) Indiana (East)
(GMT-04:00) Caracas, La Paz
(GMT-04:00) Atlantic Time (Canada)
(GMT-04:00) Santiago
(GMT-03:30) Newfoundland
(GMT-03:00) Greenland
(GMT-03:00) Brasilia
(GMT-03:00) Buenos Aires, Georgetown
(GMT-02:00) Mid-Atlantic
(GMT-01:00) Azores
(GMT-01:00) Cape Verde Is.
(GMT) Casablanca, Monrovia
(GMT) Greenwich Mean Time : Dublin, Edinburgh, Lisbon, London
(GMT+01:00) Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna
(GMT+01:00) West Central Africa
(GMT+01:00) Brussels, Copenhagen, Madrid, Paris
(GMT+01:00) Sarajevo, Skopje, Warsaw, Zagreb
(GMT+01:00) Belgrade, Bratislava, Budapest, Ljubljana, Prague
(GMT+02:00) Harare, Pretoria
(GMT+02:00) Cairo
(GMT+02:00) Jerusalem
(GMT+02:00) Helsinki, Kyiv, Riga, Sofia, Tallinn, Vilnius
(GMT+02:00) Athens, Beirut, Istanbul, Minsk
(GMT+02:00) Bucharest
(GMT+03:00) Kuwait, Riyadh
(GMT+03:00) Moscow, St. Petersburg, Volgograd
(GMT+03:00) Nairobi
(GMT+03:00) Baghdad
(GMT+03:30) Tehran
(GMT+04:00) Baku, Tbilisi, Yerevan
(GMT+04:00) Abu Dhabi, Muscat
(GMT+04:30) Kabul
(GMT+05:00) Ekaterinburg
(GMT+05:00) Islamabad, Karachi, Tashkent
(GMT+05:30) Chennai, Kolkata, Mumbai, New Delhi
(GMT+05:45) Kathmandu
(GMT+06:00) Almaty, Novosibirsk
(GMT+06:00) Astana, Dhaka
(GMT+06:00) Sri Jayawardenepura
(GMT+06:30) Rangoon
(GMT+07:00) Bangkok, Hanoi, Jakarta
(GMT+07:00) Krasnoyarsk
(GMT+08:00) Taipei
(GMT+08:00) Perth
(GMT+08:00) Kuala Lumpur, Singapore
(GMT+08:00) Irkutsk, Ulaan Bataar
(GMT+08:00) Beijing, Chongqing, Hong Kong, Urumqi
(GMT+09:00) Yakutsk
(GMT+09:00) Osaka, Sapporo, Tokyo
(GMT+09:00) Seoul
(GMT+09:30) Adelaide
(GMT+09:30) Darwin
(GMT+10:00) Canberra, Melbourne, Sydney
(GMT+10:00) Hobart
(GMT+10:00) Brisbane
(GMT+10:00) Vladivostok
(GMT+10:00) Guam, Port Moresby
(GMT+11:00) Magadan, Solomon Is., New Caledonia
(GMT+12:00) Auckland, Wellington
(GMT+12:00) Fiji, Kamchatka, Marshall Is.
(GMT+13:00) Nuku'alofa

Microsoft does not have an environmental variable that makes this offset available to you, and to get hold of it you need to query the registry. Fortunately, in all versions of Windows from NT 4 and beyond, the required tool REG.EXE is available in the support tools package or as a standard executable in the latest versions.

For those of you who are not sure if Reg.exe is installed in a Win2k server environment check for the file in the folder "c:\program files\support tools." If the folder or file is not there ask your server support people to install the support tool package from the server installation CD. The package you need is in \SUPPORT\TOOLS on the CD. If you do not want to install the whole package then you can just extract reg.exe from the file \SUPPORT\TOOLS\support.cab and copy it to either c:\WINNT or c:\WINNT\system32.

To be able to find the offset from GMT you need to know the value of the registry entry for ActiveTimeBias and the request to run is:

REG QUERY HKLM\SYSTEM\CURRENTCONTROLSET\CONTROL\
TIMEZONEINFORMATION /V ACTIVETIMEBIAS

(This should be all on one line as it is a cmd prompt command.)

Unfortunately for us the value that is returned is in hexadecimal format and should be converted to decimal to be of any use.

WebFOCUS cannot directly use this return value so a couple of options are available for you to get at it:

Option 1. Make the command part of your server or WebFOCUS Server startup script and set the value as an environment variable which can then be found using the FGETENV function. For example:

-SET &&OFFSET=FGETENV (13, 'DECIMALOFFSET', 4, 'A4');

The code to add, or the WebFOCUS startup script is:

REM extract the registry value using reg.exe and set it as an environment variable
REM the command to %%C should be on 1 line
FOR /F "tokens=1*" %%A IN ('REG.EXE QUERY 
"HKLM\SYSTEM\CURRENTCONTROLSET\CONTROL\TIMEZONEINFORMATION" 
/V ACTIVETIMEBIAS') DO FOR %%C IN (%%B) DO SET HEXOFFSET=%%C
REM set the decimal value as an environment variable
IF %HEXOFFSET%==0xfffffd6c SET DECIMALOFFSET=-660	
IF %HEXOFFSET%==0xfffffda8 SET DECIMALOFFSET=-600	
IF %HEXOFFSET%==0xfffffde4 SET DECIMALOFFSET=-540	
IF %HEXOFFSET%==0xfffffe20 SET DECIMALOFFSET=-480	
IF %HEXOFFSET%==0xfffffe5c SET DECIMALOFFSET=-420	
IF %HEXOFFSET%==0xfffffe98 SET DECIMALOFFSET=-360	
IF %HEXOFFSET%==0xfffffed4 SET DECIMALOFFSET=-300	
IF %HEXOFFSET%==0xffffff10 SET DECIMALOFFSET=-240	
IF %HEXOFFSET%==0xffffff2e SET DECIMALOFFSET=-210	
IF %HEXOFFSET%==0xffffff4c SET DECIMALOFFSET=-180	
IF %HEXOFFSET%==0xffffff88 SET DECIMALOFFSET=-120	
IF %HEXOFFSET%==0xffffffc4 SET DECIMALOFFSET=-60 
IF %HEXOFFSET%==0x0 SET DECIMALOFFSET=0
IF %HEXOFFSET%==0x3c SET DECIMALOFFSET=60
IF %HEXOFFSET%==0x78 SET DECIMALOFFSET=120
IF %HEXOFFSET%==0xb4 SET DECIMALOFFSET=180
IF %HEXOFFSET%==0xd2 SET DECIMALOFFSET=210
IF %HEXOFFSET%==0xf0 SET DECIMALOFFSET=240
IF %HEXOFFSET%==0x10e SET DECIMALOFFSET=270
IF %HEXOFFSET%==0x12c SET DECIMALOFFSET=300
IF %HEXOFFSET%==0x14a SET DECIMALOFFSET=330
IF %HEXOFFSET%==0x159 SET DECIMALOFFSET=345
IF %HEXOFFSET%==0x168 SET DECIMALOFFSET=360
IF %HEXOFFSET%==0x186 SET DECIMALOFFSET=390
IF %HEXOFFSET%==0x1a4 SET DECIMALOFFSET=420
IF %HEXOFFSET%==0x1e0 SET DECIMALOFFSET=480
IF %HEXOFFSET%==0x21c SET DECIMALOFFSET=540
IF %HEXOFFSET%==0x23a SET DECIMALOFFSET=570
IF %HEXOFFSET%==0x258 SET DECIMALOFFSET=600
IF %HEXOFFSET%==0x294 SET DECIMALOFFSET=660
IF %HEXOFFSET%==0x2d0 SET DECIMALOFFSET=720
IF %HEXOFFSET%==0x30c SET DECIMALOFFSET=780

Option 2. Generate the request in a focexec, pipe the value to a text file, and then read it in:

-* system call to write the registry value to a file
! REG QUERY HKLM\SYSTEM\CURRENTCONTROLSET\CONTROL\
TIMEZONEINFORMATION /V ACTIVETIMEBIAS > TZ.TXT
-*(above must be on one line)
-* filedef the file generated so that it can be read using 
a -READ
FILEDEF TZ DISK ./TZ.TXT (LRECL 80 RECFM V
-RUN
-* loop through the file to find the line that contains 
the required value
-LOOP
-READ TZ &LINE.A80.
-IF &LINE OMITS 'ACTIVETIMEBIAS' GOTO LOOP;
-RUN
-* extract the value using GETTOK
-SET &HEX=GETTOK(&LINE, 128, -1, 'x', 10, 'A10');.
-* decode the hex valued returned by windows to a decimal value
-SET &&OFFSET =DECODE &HEX('fffffd30' '-720'	
-                     'fffffd6c' '-660'	
-                     'fffffda8' '-600'	
-                     'fffffde4' '-540'	
-                     'fffffe20' '-480'	
-                     'fffffe5c' '-420'	
-                     'fffffe98' '-360'	
-                     'fffffed4' '-300'	
-                     'ffffff10' '-240'	
-                     'ffffff2e' '-210'	
-                     'ffffff4c' '-180'	
-                     'ffffff88' '-120'	
-                     'ffffffc4' '-60'
-                     '0' '0'
-                     '3c' '60'
-                     '78' '120'
-                     'b4' '180'
-                     'd2' '210'
-                     'f0' '240'
-                     '10e' '270'
-                     '12c' '300'
-                     '14a' '330'
-                     '159' '345'
-                     '168' '360'
-                     '186' '390'
-                     '1a4' '420'
-                     '1e0' '480'
-                     '21c' '540'
-                     '23a' '570'
-                     '258' '600'
-                     '294' '660'
-                     '2d0' '720'
-                     '30c' '780' else '0');

Notice that in the WebFOCUS version we only decode on the last part of the hex value because we need to use the "x” as the delimiter to extract the value using the GETTOK subroutine.

Now to get this to work with Susannah's ZULU code (assuming that you call the focexec timezone.fex)

Substitute

­SET &OFFSETHOURS=-4

With

-INCLUDE TIMEZONE
-SET &OFFSETHOURS =-(&&OFFSET/60);

Using the WebFOCUS approach you could add the time zone code to your site profile, and then &&OFFSET would always be available. Remember that since it is part of a site profile it would not be executed by ReportCaster.

If you already use a site profile then you just need to add the code above and it should be fine.

For those of you who are not familiar with site profiles, they are basically a preprocessing focexec that is executed every time a request is issued against the WebFOCUS server.

To set one up from scratch create the focexec in a location that is always accessed by the WebFOCUS server such as baseapp. Update either the cgivars.wfs or site.wfs file which is located in the \ibi\client53\wfc\etc subdirectory (assuming WebFOCUS 5.3). Do this through the WebFOCUS Administration Console. If doing it through the console then under Configuration, Client Settings, General, _site_profile change the \n to ­INCLUDE focexec where focexec is your focexec name. (Don't forget to save!)

To make the entry in site.wfs under Configuration, Client Settings, Custom Settings Type _site_Profile=-INCLUDE focexec after the line starting _HTML_COMMENT_VAR. (Again, remember to save!)

You should not have to reload WebFOCUS but if you have a problem restart both the Web server and WebFOCUS.

By using the same technique, any windows registry value can be made available to WebFOCUS. You just need to know the name of the key.