GMT offset code

Hideki Saito hideki at allcity.net
Sat Sep 16 20:36:52 CEST 2000


Hello.
I wrote little code that can be useful to solve timezone problem in 
GnuPG for W32.

The following code below should give GMT offset on W32.

I'm not sure if this will work for all cases. (I haven't tested 
much...and I'm not a timezone expert :)) (I think there would be 
problem on handling "half-hour" offset in some timezones.

This takes system time both in UTC format and local format, and 
returns offset. 

BTW, one of my idea of handling this correctly is to add feature on 
GnuPG that let users specify their timezone (in GMT offset) in 
'options' file like:

use-time-zone -7

Is this a bad idea?

The code follows:

-- Code begins --
float getUTCoffset(void)
{
	float offset;
	SYSTEMTIME utc;
	SYSTEMTIME local;

	GetSystemTime(&utc);
	GetLocalTime(&local);


	offset = (float)(utc.wHour - local.wHour);
	
	if(local.wDay < utc.wDay)
	{
		offset = (float)(((24 - local.wHour) + utc.wHour) * -1);
	}
	else if(local.wDay > utc.wDay)
	{
		offset = (float)(((24 + local.wHour) - utc.wHour) * -1);
	}
	else
	{
		offset = (float)(utc.wHour - local.wHour);
	}

	if(utc.wMinute - local.wMinute == 30)
	{
		offset += 0.5;
	}
	return offset;
}

-- Code ends --

Let me know if this code has problem. (I'm also learning from doing 
this :)

Thank you.

-- 
Hideki Saito mailto:hideki at allcity.net
PGP Fingerprint(0x82957B66): DE6B 1301 CC7F B915 521B  3736 4716 2919 8295 7B66



More information about the Gnupg-devel mailing list