Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find the current Time Zone name and Offest Bias

API Functions

Find the current Time Zone name and Offest Bias

by  wgcs  Posted    (Edited  )
Just use this VFP wrapper for the Kernal GetTimeZoneInformation function:

Code:
FUNCTION GetTimeZone( pcFunc )
* Purpose: Return the Time Zone bias or description
*   Input: pcFunc = "BIAS" or Missing... return the bias in Minutes
*                     ( GMT = LocalTime + Bias )
*          pcFunc = "NAME" ... Return the time zone name.
*  Author: William GC Steinford
***********************************************************

*!*	typedef struct _TIME_ZONE_INFORMATION { 
*!*	    LONG       Bias;                    2:  1-  2
*!*	    WCHAR      StandardName[ 32 ];     64:  3- 66
*!*	    SYSTEMTIME StandardDate;           16: 67- 82
*!*	    LONG       StandardBias;            2: 83- 84
*!*	    WCHAR      DaylightName[ 32 ];     64: 85-148
*!*	    SYSTEMTIME DaylightDate;           16:149-164
*!*	    LONG       DaylightBias;            2:165-166
*!*	} TIME_ZONE_INFORMATION, *PTIME_ZONE_INFORMATION; 
*!*	typedef struct _SYSTEMTIME { 
*!*	    WORD wYear; 
*!*	    WORD wMonth; 
*!*	    WORD wDayOfWeek; 
*!*	    WORD wDay; 
*!*	    WORD wHour; 
*!*	    WORD wMinute; 
*!*	    WORD wSecond; 
*!*	    WORD wMilliseconds; 
*!*	} SYSTEMTIME, *PSYSTEMTIME; 
LOCAL lcTZInfo, lcDesc
lcTZInfo = num2dword(0);
           +repl(chr(0),64)+repl(num2Word(0),8)+num2dword(0);
           +repl(chr(0),64)+repl(num2Word(0),8)+num2dword(0)
DECLARE INTEGER GetTimeZoneInformation IN kernel32.dll; 
    STRING @ lpTimeZoneInformation 
#DEFINE TIME_ZONE_ID_INVALID  0xFFFFFFFF
#DEFINE TIME_ZONE_ID_UNKNOWN  0
#DEFINE TIME_ZONE_ID_STANDARD 1
#DEFINE TIME_ZONE_ID_DAYLIGHT 2
lcRes = GetTimeZoneInformation( @lcTZInfo )
lnBias = Buf2DWord( lcTZInfo )
lcDesc = "Unknown"
do case
  case lcRes=TIME_ZONE_ID_STANDARD
    lcDesc = substr( lcTZInfo, 3, 64 )
    lcDesc = StrConv( lcDesc, 6 ) && 6=Unicode(wide)->DoubleByte
    lcDesc = strTran( lcDesc, chr(0), ' )
  case lcRes=TIME_ZONE_ID_DAYLIGHT
    lcDesc = substr( lcTZInfo, 3, 64 )
    lcDesc = StrConv( lcDesc, 6 )
    lcDesc = strTran( lcDesc, chr(0), ' )
endcase
if varType(pcFunc)='C' and pcFunc='NAME'
  RETURN lcDesc
endif
RETURN lnBias
****************************************************

* * *
* dword is compatible with LONG
FUNCTION  num2dword (lnValue) 
#DEFINE m0       256 
#DEFINE m1     65536 
#DEFINE m2  16777216 
    LOCAL b0, b1, b2, b3 
    b3 = Int(lnValue/m2) 
    b2 = Int((lnValue - b3*m2)/m1) 
    b1 = Int((lnValue - b3*m2 - b2*m1)/m0) 
    b0 = Mod(lnValue, m0) 
RETURN Chr(b0)+Chr(b1)+Chr(b2)+Chr(b3) 
* * *
* dword is compatible with LONG
FUNCTION  num2word (lnValue) 
RETURN Chr(MOD(m.lnValue,256)) + CHR(INT(m.lnValue/256)) 
* * * 
FUNCTION  buf2word (lcBuffer) 
RETURN Asc(SUBSTR(lcBuffer, 1,1)) + ; 
    Asc(SUBSTR(lcBuffer, 2,1)) * 256 
* * *
FUNCTION  buf2dword (lcBuffer)  
RETURN;  
    Asc(SUBSTR(lcBuffer, 1,1)) + ;  
    Asc(SUBSTR(lcBuffer, 2,1)) * 256 +;  
    Asc(SUBSTR(lcBuffer, 3,1)) * 65536 +;  
    Asc(SUBSTR(lcBuffer, 4,1)) * 16777216  
ENDFUNC
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top