Mailing-List: contact cygwin-developers-help AT sourceware DOT cygnus DOT com; run by ezmlm Sender: cygwin-developers-owner AT sourceware DOT cygnus DOT com Delivered-To: mailing list cygwin-developers AT sourceware DOT cygnus DOT com From: "Norbert Schulze" To: Subject: (patch) daylight saving Date: Sat, 1 May 1999 18:14:32 +0200 Message-ID: <000101be93ed$ba075ed0$3a5ac5c1@guinan> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_0002_01BE93FE.7D902ED0" X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook 8.5, Build 4.71.2377.0 Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300 This is a multi-part message in MIME format. ------=_NextPart_000_0002_01BE93FE.7D902ED0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit The attached patch adds and corrects daylight saving in timezone(), gettimeofday(), localtime() and tzset(). Regards Norbert ------=_NextPart_000_0002_01BE93FE.7D902ED0 Content-Type: application/octet-stream; name="times.cc-patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="times.cc-patch" --- times.orig Tue Feb 02 20:01:06 1999 +++ times.cc Sun Apr 04 18:31:46 1999 @@ -104,9 +104,18 @@ timezone () #else static NO_COPY char b[20]; #endif + DWORD tzid; TIME_ZONE_INFORMATION tz; - GetTimeZoneInformation (&tz); - __small_sprintf (b,"GMT-%d:00", (int) (tz.Bias / 60)); + LONG Bias; + + tzid =3D GetTimeZoneInformation (&tz); + + if (tzid =3D=3D TIME_ZONE_ID_DAYLIGHT) + Bias =3D tz.Bias + tz.DaylightBias; + else + Bias =3D tz.Bias + tz.StandardBias; + + sprintf (b,"GMT%+d:%02d", (int) (-Bias / 60), (int) (abs(Bias) % = 60)); return b; } =20 @@ -124,7 +133,6 @@ totimeval (struct timeval *dst, FILETIME } =20 /* gettimeofday: BSD */ -/* FIXME: ignores daylight savings time bias? */ extern "C" int gettimeofday (struct timeval *p, struct timezone *z) @@ -132,11 +140,17 @@ gettimeofday (struct timeval *p, struct=20 int res =3D 0; DWORD tzid; TIME_ZONE_INFORMATION tz; + LONG Bias; =20 tzid =3D GetTimeZoneInformation (&tz); if (tzid =3D=3D TIME_ZONE_ID_INVALID) res =3D -1; =20 + if (tzid =3D=3D TIME_ZONE_ID_DAYLIGHT) + Bias =3D tz.Bias + tz.DaylightBias; + else + Bias =3D tz.Bias + tz.StandardBias; + if (p !=3D NULL) { SYSTEMTIME t; @@ -144,14 +158,14 @@ gettimeofday (struct timeval *p, struct=20 =20 GetSystemTime (&t); if (! SystemTimeToFileTime (&t, &f)) - res =3D -1; - totimeval (p, &f, tz.Bias * 60, 1); + res =3D -1; + totimeval (p, &f, Bias * 60, 1); } =20 if (z !=3D NULL) { - z->tz_minuteswest =3D tz.Bias; - z->tz_dsttime =3D tz.DaylightBias !=3D 0; + z->tz_minuteswest =3D Bias; + z->tz_dsttime =3D (tzid =3D=3D TIME_ZONE_ID_DAYLIGHT); } =20 syscall_printf ("%d =3D gettimeofday (%x, %x)", res, p, z); @@ -381,31 +395,19 @@ localtime (const time_t *tim_p) { time_t tim =3D *tim_p; struct tm *rtm; - + DWORD tzid; TIME_ZONE_INFORMATION tz; - GetTimeZoneInformation (&tz); - tim -=3D tz.Bias * SECSPERMIN; + + tzid =3D GetTimeZoneInformation (&tz); + + if (tzid =3D=3D TIME_ZONE_ID_DAYLIGHT) + tim -=3D (tz.Bias + tz.DaylightBias) * SECSPERMIN; + else + tim -=3D (tz.Bias + tz.StandardBias) * SECSPERMIN; =20 rtm =3D corelocaltime (&tim); =20 - { - /* tm_mon starts at zero, wMonth starts at 1 */ -#define MON_MAX 32 - int toy_tim =3D (MON_MAX * (rtm->tm_mon + 1)) + rtm->tm_mday; - int toy_dst_start =3D (MON_MAX * tz.DaylightDate.wMonth) + - tz.DaylightDate.wDay; - - int toy_dst_stop =3D (MON_MAX * tz.StandardDate.wMonth) + - tz.StandardDate.wDay; - if ((toy_tim > toy_dst_start) && (toy_tim < toy_dst_stop)) - { - tim -=3D tz.DaylightBias * 60; - rtm =3D corelocaltime (&tim); - rtm->tm_isdst =3D 1; - } - else - rtm->tm_isdst =3D 0; - } + rtm->tm_isdst =3D (tzid =3D=3D TIME_ZONE_ID_DAYLIGHT); =20 syscall_printf ("%x =3D localtime (%x)", rtm, tim_p); =20 @@ -577,12 +579,16 @@ tzset () Right now it just always sets information based on the system time zone. */ =20 + DWORD tzid; TIME_ZONE_INFORMATION tz; =20 - GetTimeZoneInformation (&tz); + tzid =3D GetTimeZoneInformation (&tz); =20 - _timezone =3D tz.Bias * SECSPERMIN; - _daylight =3D tz.DaylightBias !=3D 0; + if (tzid =3D=3D TIME_ZONE_ID_DAYLIGHT) + _timezone =3D (tz.Bias + tz.DaylightBias) * SECSPERMIN; + else + _timezone =3D (tz.Bias + tz.StandardBias) * SECSPERMIN; + _daylight =3D (tzid =3D=3D TIME_ZONE_ID_DAYLIGHT); WideCharToMultiByte (CP_ACP, 0, tz.StandardName, -1, buf1, sizeof = buf1 - 1, NULL, NULL); buf1[sizeof buf1 - 1] =3D '\0'; ------=_NextPart_000_0002_01BE93FE.7D902ED0--