Skip to content

Commit 0a27444

Browse files
author
Thomas G. Lockhart
committed
Change ordering of HAVE_TM_ZONE and HAVE_INT_TIMEZONE code blocks
to give HAVE_TM_ZONE priority. This fixes glibc2 machines and any other machine which passes both tests in configure. Repair HAVE_TM_ZONE code which stuffs tm structure with date type values. Same problems as were originally there before v6.1, but never noticed. Thanks to Oleg for nagging :)
1 parent 1e64216 commit 0a27444

File tree

3 files changed

+76
-52
lines changed

3 files changed

+76
-52
lines changed

src/backend/utils/adt/datetime.c

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/datetime.c,v 1.25 1998/09/01 03:25:54 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/datetime.c,v 1.25.2.1 1998/12/31 16:34:47 thomas Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -339,7 +339,7 @@ abstime_date(AbsoluteTime abstime)
339339
* and then convert again to try to get the time zones correct.
340340
*/
341341
static int
342-
date2tm(DateADT dateVal, int *tzp, struct tm * tm, double *fsec, char **tzn)
342+
date2tm(DateADT dateVal, int *tzp, struct tm *tm, double *fsec, char **tzn)
343343
{
344344
struct tm *tx;
345345
time_t utime;
@@ -357,14 +357,18 @@ date2tm(DateADT dateVal, int *tzp, struct tm * tm, double *fsec, char **tzn)
357357

358358
/* convert to system time */
359359
utime = ((dateVal + (date2j(2000, 1, 1) - date2j(1970, 1, 1))) * 86400);
360-
utime += (12 * 60 * 60);/* rotate to noon to get the right day in
361-
* time zone */
360+
/* rotate to noon to get the right day in time zone */
361+
utime += (12 * 60 * 60);
362362

363363
#ifdef USE_POSIX_TIME
364364
tx = localtime(&utime);
365365

366366
#ifdef DATEDEBUG
367-
#ifdef HAVE_INT_TIMEZONE
367+
#if defined(HAVE_TM_ZONE)
368+
printf("date2tm- (localtime) %d.%02d.%02d %02d:%02d:%02.0f %s dst=%d\n",
369+
tx->tm_year, tx->tm_mon, tx->tm_mday, tx->tm_hour, tx->tm_min, (double) tm->tm_sec,
370+
tx->tm_zone, tx->tm_isdst);
371+
#elif defined(HAVE_INT_TIMEZONE)
368372
printf("date2tm- (localtime) %d.%02d.%02d %02d:%02d:%02.0f %s %s dst=%d\n",
369373
tx->tm_year, tx->tm_mon, tx->tm_mday, tx->tm_hour, tx->tm_min, (double) tm->tm_sec,
370374
tzname[0], tzname[1], tx->tm_isdst);
@@ -375,21 +379,21 @@ date2tm(DateADT dateVal, int *tzp, struct tm * tm, double *fsec, char **tzn)
375379
tm->tm_mday = tx->tm_mday;
376380
tm->tm_isdst = tx->tm_isdst;
377381

378-
#ifdef HAVE_INT_TIMEZONE
379-
*tzp = (tm->tm_isdst ? (timezone - 3600) : timezone);
380-
if (tzn != NULL)
381-
*tzn = tzname[(tm->tm_isdst > 0)];
382-
383-
#else /* !HAVE_INT_TIMEZONE */
382+
#if defined(HAVE_TM_ZONE)
384383
tm->tm_gmtoff = tx->tm_gmtoff;
385384
tm->tm_zone = tx->tm_zone;
386385

387-
*tzp = (tm->tm_isdst ? (tm->tm_gmtoff - 3600) : tm->tm_gmtoff); /* tm_gmtoff is
388-
* Sun/DEC-ism */
386+
/* tm_gmtoff is Sun/DEC-ism */
387+
*tzp = -(tm->tm_gmtoff);
388+
if (tzn != NULL)
389+
*tzn = (char *)tm->tm_zone;
390+
#elif defined(HAVE_INT_TIMEZONE)
391+
*tzp = (tm->tm_isdst ? (timezone - 3600) : timezone);
389392
if (tzn != NULL)
390-
*tzn = tm->tm_zone;
393+
*tzn = tzname[(tm->tm_isdst > 0)];
394+
#else
395+
#error USE_POSIX_TIME is defined but neither HAVE_TM_ZONE or HAVE_INT_TIMEZONE are defined
391396
#endif
392-
393397
#else /* !USE_POSIX_TIME */
394398
*tzp = CTimeZone; /* V7 conventions; don't know timezone? */
395399
if (tzn != NULL)
@@ -411,6 +415,18 @@ date2tm(DateADT dateVal, int *tzp, struct tm * tm, double *fsec, char **tzn)
411415
*tzn = NULL;
412416
}
413417

418+
#ifdef DATEDEBUG
419+
#if defined(HAVE_TM_ZONE)
420+
printf("date2tm- %d.%02d.%02d %02d:%02d:%02.0f (%d %s) dst=%d\n",
421+
tm->tm_year, tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, (double) tm->tm_sec,
422+
*tzp, tm->tm_zone, tm->tm_isdst);
423+
#elif defined(HAVE_INT_TIMEZONE)
424+
printf("date2tm- %d.%02d.%02d %02d:%02d:%02.0f (%d %s %s) dst=%d\n",
425+
tm->tm_year, tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, (double) tm->tm_sec,
426+
*tzp, tzname[0], tzname[1], tm->tm_isdst);
427+
#endif
428+
#endif
429+
414430
return 0;
415431
} /* date2tm() */
416432

src/backend/utils/adt/dt.c

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/dt.c,v 1.59 1998/10/08 18:30:07 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/dt.c,v 1.59.2.1 1998/12/31 16:34:48 thomas Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -1454,11 +1454,12 @@ datetime_trunc(text *units, DateTime *datetime)
14541454
tm->tm_year += 1900;
14551455
tm->tm_mon += 1;
14561456

1457-
#ifdef HAVE_INT_TIMEZONE
1458-
tz = ((tm->tm_isdst > 0) ? (timezone - 3600) : timezone);
1459-
1460-
#else /* !HAVE_INT_TIMEZONE */
1457+
#if defined(HAVE_TM_ZONE)
14611458
tz = -(tm->tm_gmtoff); /* tm_gmtoff is Sun/DEC-ism */
1459+
#elif defined(HAVE_INT_TIMEZONE)
1460+
tz = ((tm->tm_isdst > 0) ? (timezone - 3600) : timezone);
1461+
#else
1462+
#error USE_POSIX_TIME is defined but neither HAVE_TM_ZONE or HAVE_INT_TIMEZONE are defined
14621463
#endif
14631464

14641465
#else /* !USE_POSIX_TIME */
@@ -2414,16 +2415,17 @@ datetime2tm(DateTime dt, int *tzp, struct tm * tm, double *fsec, char **tzn)
24142415
#ifdef USE_POSIX_TIME
24152416
tx = localtime(&utime);
24162417
#ifdef DATEDEBUG
2417-
#ifdef HAVE_INT_TIMEZONE
2418+
#if defined(HAVE_TM_ZONE)
2419+
printf("datetime2tm- (localtime) %d.%02d.%02d %02d:%02d:%02.0f %s dst=%d\n",
2420+
tx->tm_year, tx->tm_mon, tx->tm_mday, tx->tm_hour, tx->tm_min, sec,
2421+
tx->tm_zone, tx->tm_isdst);
2422+
#elif defined(HAVE_INT_TIMEZONE)
24182423
printf("datetime2tm- (localtime) %d.%02d.%02d %02d:%02d:%02.0f %s %s dst=%d\n",
24192424
tx->tm_year, tx->tm_mon, tx->tm_mday, tx->tm_hour, tx->tm_min, sec,
24202425
tzname[0], tzname[1], tx->tm_isdst);
24212426
#else
2422-
printf("datetime2tm- (localtime) %d.%02d.%02d %02d:%02d:%02.0f %s dst=%d\n",
2423-
tx->tm_year, tx->tm_mon, tx->tm_mday, tx->tm_hour, tx->tm_min, sec,
2424-
tx->tm_zone, tx->tm_isdst);
2427+
#error USE_POSIX_TIME is defined but neither HAVE_TM_ZONE or HAVE_INT_TIMEZONE are defined
24252428
#endif
2426-
#else
24272429
#endif
24282430
tm->tm_year = tx->tm_year + 1900;
24292431
tm->tm_mon = tx->tm_mon + 1;
@@ -2442,18 +2444,19 @@ datetime2tm(DateTime dt, int *tzp, struct tm * tm, double *fsec, char **tzn)
24422444
#endif
24432445
tm->tm_isdst = tx->tm_isdst;
24442446

2445-
#ifdef HAVE_INT_TIMEZONE
2446-
*tzp = (tm->tm_isdst ? (timezone - 3600) : timezone);
2447-
if (tzn != NULL)
2448-
*tzn = tzname[(tm->tm_isdst > 0)];
2449-
2450-
#else /* !HAVE_INT_TIMEZONE */
2447+
#if defined(HAVE_TM_ZONE)
24512448
tm->tm_gmtoff = tx->tm_gmtoff;
24522449
tm->tm_zone = tx->tm_zone;
24532450

24542451
*tzp = -(tm->tm_gmtoff); /* tm_gmtoff is Sun/DEC-ism */
24552452
if (tzn != NULL)
2456-
*tzn = tm->tm_zone;
2453+
*tzn = (char *)tm->tm_zone;
2454+
#elif defined(HAVE_INT_TIMEZONE)
2455+
*tzp = (tm->tm_isdst ? (timezone - 3600) : timezone);
2456+
if (tzn != NULL)
2457+
*tzn = tzname[(tm->tm_isdst > 0)];
2458+
#else
2459+
#error USE_POSIX_TIME is defined but neither HAVE_TM_ZONE or HAVE_INT_TIMEZONE are defined
24572460
#endif
24582461

24592462
#else /* !USE_POSIX_TIME */
@@ -2488,7 +2491,10 @@ datetime2tm(DateTime dt, int *tzp, struct tm * tm, double *fsec, char **tzn)
24882491

24892492
#ifdef DATEDEBUG
24902493
#ifdef USE_POSIX_TIME
2491-
#ifdef HAVE_INT_TIMEZONE
2494+
#if defined(HAVE_TM_ZONE)
2495+
printf("datetime2tm- timezone is %s; offset is %d\n",
2496+
tm->tm_zone, ((tzp != NULL) ? *tzp : 0));
2497+
#elif defined(HAVE_INT_TIMEZONE)
24922498
printf("datetime2tm- timezone is %s; offset is %d (%d); daylight is %d\n",
24932499
tzname[tm->tm_isdst != 0], ((tzp != NULL) ? *tzp : 0), CTimeZone, CDayLight);
24942500
#endif
@@ -3034,11 +3040,12 @@ DecodeDateTime(char **field, int *ftype, int nf,
30343040
tm->tm_year += 1900;
30353041
tm->tm_mon += 1;
30363042

3037-
#ifdef HAVE_INT_TIMEZONE
3038-
*tzp = ((tm->tm_isdst > 0) ? (timezone - 3600) : timezone);
3039-
3040-
#else /* !HAVE_INT_TIMEZONE */
3043+
#if defined(HAVE_TM_ZONE)
30413044
*tzp = -(tm->tm_gmtoff); /* tm_gmtoff is Sun/DEC-ism */
3045+
#elif defined(HAVE_INT_TIMEZONE)
3046+
*tzp = ((tm->tm_isdst > 0) ? (timezone - 3600) : timezone);
3047+
#else
3048+
#error USE_POSIX_TIME is defined but neither HAVE_TM_ZONE or HAVE_INT_TIMEZONE are defined
30423049
#endif
30433050

30443051
#else /* !USE_POSIX_TIME */
@@ -4104,12 +4111,14 @@ EncodeDateTime(struct tm * tm, double fsec, int *tzp, char **tzn, int style, cha
41044111

41054112
#ifdef DATEDEBUG
41064113
#ifdef USE_POSIX_TIME
4107-
#ifdef HAVE_INT_TIMEZONE
4114+
#if defined(HAVE_TM_ZONE)
4115+
printf("EncodeDateTime- timezone is %s (%s); offset is %ld (%d); daylight is %d (%d)\n",
4116+
*tzn, tm->tm_zone, (-tm->tm_gmtoff), CTimeZone, tm->tm_isdst, CDayLight);
4117+
#elif defined(HAVE_INT_TIMEZONE)
41084118
printf("EncodeDateTime- timezone is %s (%s); offset is %d (%d); daylight is %d (%d)\n",
41094119
*tzn, tzname[0], *tzp, CTimeZone, tm->tm_isdst, CDayLight);
41104120
#else
4111-
printf("EncodeDateTime- timezone is %s (%s); offset is %ld (%d); daylight is %d (%d)\n",
4112-
*tzn, tm->tm_zone, (-tm->tm_gmtoff), CTimeZone, tm->tm_isdst, CDayLight);
4121+
#error USE_POSIX_TIME is defined but neither HAVE_TM_ZONE or HAVE_INT_TIMEZONE are defined
41134122
#endif
41144123
#else
41154124
printf("EncodeDateTime- timezone is %s (%s); offset is %d; daylight is %d\n",

src/backend/utils/adt/nabstime.c

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/nabstime.c,v 1.46.2.2 1998/12/19 03:23:18 thomas Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/nabstime.c,v 1.46.2.3 1998/12/31 16:34:48 thomas Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -61,7 +61,7 @@ GetCurrentAbsoluteTime(void)
6161
if (!HasCTZSet)
6262
{
6363
#ifdef USE_POSIX_TIME
64-
#ifdef HAVE_TM_ZONE
64+
#if defined(HAVE_TM_ZONE)
6565
tm = localtime(&now);
6666

6767
CTimeZone = -tm->tm_gmtoff; /* tm_gmtoff is Sun/DEC-ism */
@@ -90,9 +90,8 @@ GetCurrentAbsoluteTime(void)
9090
CTimeZone = tb.timezone * 60;
9191
CDayLight = (tb.dstflag != 0);
9292

93-
/*
94-
* XXX does this work to get the local timezone string in V7? -
95-
* tgl 97/03/18
93+
/* XXX does this work to get the local timezone string in V7?
94+
* - tgl 97/03/18
9695
*/
9796
strftime(CTZName, MAXTZLEN, "%Z", localtime(&now));
9897
#endif
@@ -140,14 +139,14 @@ abstime2tm(AbsoluteTime time, int *tzp, struct tm * tm, char *tzn)
140139
#endif
141140

142141
#if defined(DATEDEBUG)
143-
#if (! defined(HAVE_TM_ZONE)) && defined(HAVE_INT_TIMEZONE)
144-
printf("datetime2tm- (localtime) %d.%02d.%02d %02d:%02d:%02d %s %s dst=%d\n",
145-
tx->tm_year, tx->tm_mon, tx->tm_mday, tx->tm_hour, tx->tm_min, tx->tm_sec,
146-
tzname[0], tzname[1], tx->tm_isdst);
147-
#else
142+
#if defined(HAVE_TM_ZONE)
148143
printf("datetime2tm- (localtime) %d.%02d.%02d %02d:%02d:%02d %s dst=%d\n",
149144
tx->tm_year, tx->tm_mon, tx->tm_mday, tx->tm_hour, tx->tm_min, tx->tm_sec,
150145
tx->tm_zone, tx->tm_isdst);
146+
#elif defined(HAVE_INT_TIMEZONE)
147+
printf("datetime2tm- (localtime) %d.%02d.%02d %02d:%02d:%02d %s %s dst=%d\n",
148+
tx->tm_year, tx->tm_mon, tx->tm_mday, tx->tm_hour, tx->tm_min, tx->tm_sec,
149+
tzname[0], tzname[1], tx->tm_isdst);
151150
#endif
152151
#endif
153152

@@ -161,7 +160,7 @@ abstime2tm(AbsoluteTime time, int *tzp, struct tm * tm, char *tzn)
161160
tm->tm_sec = tx->tm_sec;
162161
tm->tm_isdst = tx->tm_isdst;
163162

164-
#ifdef HAVE_TM_ZONE
163+
#if defined(HAVE_TM_ZONE)
165164
tm->tm_gmtoff = tx->tm_gmtoff;
166165
tm->tm_zone = tx->tm_zone;
167166

@@ -175,7 +174,7 @@ abstime2tm(AbsoluteTime time, int *tzp, struct tm * tm, char *tzn)
175174
*tzp = (tm->tm_isdst ? (timezone - 3600) : timezone);
176175
if (tzn != NULL)
177176
strcpy(tzn, tzname[tm->tm_isdst]);
178-
#else /* !HAVE_INT_TIMEZONE */
177+
#else
179178
#error POSIX time support is broken
180179
#endif
181180
#else /* ! USE_POSIX_TIME */

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy