#include #include #include #include #include #include #ifdef __GNUC__ static long _dstbias=0; #endif void win32_tzset( void ) { tzset(); if (((char*)getenv("TZ") == (char*)NULL) && (_timezone == 0)) { TIME_ZONE_INFORMATION tzinfo; DWORD tzstate; int dstflag=0; static char TZ[40]; char tmp_str[40]; long i,j,g,k; /* printf("try to build up a TZ Variable from Windows Date Control Panel!\n"); */ if ( (tzstate = GetTimeZoneInformation( &tzinfo )) != 0xFFFFFFFF ) { /* * Must be very careful in determining whether or not DST is * really in effect. */ if ( (tzstate == TIME_ZONE_ID_DAYLIGHT) && (tzinfo.DaylightDate.wMonth != 0) && (tzinfo.DaylightBias != 0) ) dstflag = 1; else /* * When in doubt, assume standard time */ dstflag = 0; } else dstflag = 0; /* When in doubt, assume standard time */ _timezone = tzinfo.Bias * 60L; if ( tzinfo.StandardDate.wMonth != 0 ) _timezone += (tzinfo.StandardBias * 60L); if ( (tzinfo.DaylightDate.wMonth != 0) && (tzinfo.DaylightBias != 0) ) { _daylight = 1; _dstbias = (tzinfo.DaylightBias - tzinfo.StandardBias) * 60L; } else { _daylight = 0; _dstbias = 0; } _tzname[0] = "GMT"; _tzname[1] = "DST"; /* BUILD UP TZ STRING */ /* always relativ to GMT Time */ strcpy(TZ,"TZ=GMT"); /* probably UTC for Universal StandardTime */ if (_timezone > 0) { strcat(TZ,"+"); i=_timezone; } else { strcat(TZ,"-"); i=_timezone * -1; } j=i % 60L; /* Minutenausgleich */ g=j % 60L; /* Sekundenausgleich */ i=i / 3600L; sprintf(tmp_str,"%ld", i); strcat(TZ,tmp_str); if (j | g) { sprintf(tmp_str,":%ld", j); strcat(TZ,tmp_str); } if (g) { sprintf(tmp_str,":%ld", g); strcat(TZ,tmp_str); } if (_daylight) { strcat(TZ,"DST"); /* DaylightSavingTime */ k=_timezone + _dstbias; /* absolut differenz */ if (k > 0) { strcat(TZ,"+"); i=k; } else { strcat(TZ,"-"); i=k * -1; } j=i % 60L; /* Minutenausgleich */ g=j % 60L; /* Sekundenausgleich */ i=i / 3600L; sprintf(tmp_str,"%ld", i); strcat(TZ,tmp_str); if (j | g) { sprintf(tmp_str,":%ld", j); strcat(TZ,tmp_str); } if (g) { sprintf(tmp_str,":%ld", g); strcat(TZ,tmp_str); } /* when to switch DST on ?*/ sprintf(tmp_str,",M%d.%d.%d/%d", tzinfo.DaylightDate.wMonth, tzinfo.DaylightDate.wDay, tzinfo.DaylightDate.wDayOfWeek tzinfo.DaylightDate.wHour); strcat(TZ,tmp_str); if (tzinfo.DaylightDate.wMinute || tzinfo.DaylightDate.wSecond) { sprintf(tmp_str,",:%d", tzinfo.DaylightDate.wMinute); strcat(TZ,tmp_str); } if (tzinfo.DaylightDate.wSecond) { sprintf(tmp_str,",:%d", tzinfo.DaylightDate.wSecond); strcat(TZ,tmp_str); } /* when to switch DST off, back to StandardDate ?*/ sprintf(tmp_str,",M%d.%d.%d/%d", tzinfo.StandardDate.wMonth, tzinfo.StandardDate.wDay, tzinfo.StandardDate.wDayOfWeek, tzinfo.StandardDate.wHour); strcat(TZ,tmp_str); if (tzinfo.StandardDate.wMinute || tzinfo.StandardDate.wSecond) { sprintf(tmp_str,",:%d", tzinfo.StandardDate.wMinute); strcat(TZ,tmp_str); } if (tzinfo.StandardDate.wSecond) { sprintf(tmp_str,",:%d", tzinfo.StandardDate.wSecond); strcat(TZ,tmp_str); } } /* printf("\nbuild up TZ string: TZ=%s\n", TZ); */ putenv(TZ); setenv } tzset(); /* set to system & cygwin */ }