Error obtaining PC timezone from GetTimeZoneInformation

 

Dear all,


I have encountered the below error(showing on the Experts tab) with getting the time zone:

Error obtaining PC timezone from GetTimeZoneInformation in kernel32.dll. Returning 0


My PC timezone is GMT (+08:00), no matter which one I set(perth, taipei, bejing), it always show the above error.


Can someone advise how to resolve it.


Source:


#import "kernel32.dll"
int  GetTimeZoneInformation(int& TZInfoArray[]);
#import

#define TIME_ZONE_ID_UNKNOWN   0
#define TIME_ZONE_ID_STANDARD  1
#define TIME_ZONE_ID_DAYLIGHT  2

// Local timezone in hours, adjusting for daylight saving
double TimeZoneLocal()
{
int TZInfoArray[43];

switch(GetTimeZoneInformation(TZInfoArray))
{
case TIME_ZONE_ID_UNKNOWN:
Print("Error obtaining PC timezone from GetTimeZoneInformation in kernel32.dll. Returning 0");
return(0);

case TIME_ZONE_ID_STANDARD:
return(TZInfoArray[0]/(-60.0));

case TIME_ZONE_ID_DAYLIGHT:
return((TZInfoArray[0]+TZInfoArray[42])/(-60.0));

default:
Print("Unkown return value from GetTimeZoneInformation in kernel32.dll. Returning 0");
return(0);
}
}

// Server timezone in hours
double TimeZoneServer()
{
int ServerToLocalDiffMinutes = (TimeCurrent()-TimeLocal())/60;

// round to nearest 30 minutes to allow for inaccurate PC clock
int nHalfHourDiff = MathRound(ServerToLocalDiffMinutes/30.0);
ServerToLocalDiffMinutes = nHalfHourDiff*30;
return(TimeZoneLocal() + ServerToLocalDiffMinutes/60.0);
}

// Uses local PC time, local PC timezone, and server time to calculate GMT time at arrival of last tick
datetime TimeGMT()
{
// two ways of calculating
// 1. From PC time, which may not be accurate
// 2. From server time. Most accurate except when server is down on weekend
datetime dtGmtFromLocal = TimeLocal() - TimeZoneLocal()*3600;
datetime dtGmtFromServer = TimeCurrent() - TimeZoneServer()*3600;

// return local-derived value if server value is out by more than 5 minutes, eg during weekend
if (dtGmtFromLocal > dtGmtFromServer + 300)
{
return(dtGmtFromLocal);
}
else
{
return(dtGmtFromServer);
}
}
 

GetTimeZoneInformation will return the right Bias even when it return TIME_ZONE_ID_UNKNOWN, so the function TimeZoneLocal() just need be modify to:

double TimeZoneLocal()
{
	int TZInfoArray[43];

	if(GetTimeZoneInformation(TZInfoArray)==TIME_ZONE_ID_DAYLIGHT)
		return((TZInfoArray[0]+TZInfoArray[42])/(-60.0));
	else//TIME_ZONE_ID_STANDARD or TIME_ZONE_ID_UNKNOWN
		return(TZInfoArray[0]/(-60.0));
}
Reason: