Simplify timezone-handling code per proposal to pghackers: get rid of

setting timezone-related variables during transaction start.  They were
not used anyway in platforms that HAVE_TM_ZONE or HAVE_INT_TIMEZONE,
which it appears is *all* the platforms we are currently supporting.
For platforms that have neither, we now only support UTC or numeric-
offset-from-UTC timezones.
This commit is contained in:
Tom Lane 2003-02-22 05:57:45 +00:00
parent 799bc58dc7
commit 80d6a277c9
5 changed files with 43 additions and 179 deletions

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/datetime.c,v 1.101 2003/02/20 05:24:55 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/datetime.c,v 1.102 2003/02/22 05:57:44 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -1604,8 +1604,9 @@ DetermineLocalTimeZone(struct tm * tm)
tz = (int) delta2;
}
#else /* not (HAVE_TM_ZONE || HAVE_INT_TIMEZONE) */
/* Assume UTC if no system timezone info available */
tm->tm_isdst = 0;
tz = CTimeZone;
tz = 0;
#endif
}
else

View File

@ -1,4 +1,5 @@
/*-------------------------------------------------------------------------
*
* nabstime.c
* Utilities for the built-in type "AbsoluteTime".
* Functions for the built-in type "RelativeTime".
@ -9,9 +10,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/nabstime.c,v 1.103 2003/02/20 05:24:55 tgl Exp $
*
* NOTES
* $Header: /cvsroot/pgsql/src/backend/utils/adt/nabstime.c,v 1.104 2003/02/22 05:57:45 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -23,10 +22,6 @@
#include <float.h>
#include <limits.h>
#if !(defined(HAVE_TM_ZONE) || defined(HAVE_INT_TIMEZONE))
#include <sys/timeb.h>
#endif
#include "access/xact.h"
#include "miscadmin.h"
#include "utils/builtins.h"
@ -88,78 +83,25 @@ static int istinterval(char *i_string,
/* GetCurrentAbsoluteTime()
* Get the current system time. Set timezone parameters if not specified elsewhere.
* Define HasCTZSet to allow clients to specify the default timezone.
* Get the current system time.
*
* Returns the number of seconds since epoch (January 1 1970 GMT)
* Returns the number of seconds since epoch (January 1 1970 GMT).
*/
AbsoluteTime
GetCurrentAbsoluteTime(void)
{
time_t now;
#if defined(HAVE_TM_ZONE) || defined(HAVE_INT_TIMEZONE)
struct tm *tm;
now = time(NULL);
#else
struct timeb tb; /* the old V7-ism */
ftime(&tb);
now = tb.time;
#endif
if (!HasCTZSet)
{
#if defined(HAVE_TM_ZONE)
tm = localtime(&now);
CTimeZone = -tm->tm_gmtoff; /* tm_gmtoff is Sun/DEC-ism */
CDayLight = (tm->tm_isdst > 0);
#ifdef NOT_USED
/*
* XXX is there a better way to get local timezone string w/o
* tzname? - tgl 97/03/18
*/
strftime(CTZName, MAXTZLEN, "%Z", tm);
#endif
/*
* XXX FreeBSD man pages indicate that this should work - thomas
* 1998-12-12
*/
StrNCpy(CTZName, tm->tm_zone, MAXTZLEN+1);
#elif defined(HAVE_INT_TIMEZONE)
tm = localtime(&now);
CDayLight = tm->tm_isdst;
CTimeZone = ((tm->tm_isdst > 0) ? (TIMEZONE_GLOBAL - 3600) : TIMEZONE_GLOBAL);
StrNCpy(CTZName, tzname[tm->tm_isdst], MAXTZLEN+1);
#else /* neither HAVE_TM_ZONE nor
* HAVE_INT_TIMEZONE */
CTimeZone = tb.timezone * 60;
CDayLight = (tb.dstflag != 0);
/*
* XXX does this work to get the local timezone string in V7? -
* tgl 97/03/18
*/
strftime(CTZName, MAXTZLEN, "%Z", localtime(&now));
#endif
}
return (AbsoluteTime) now;
} /* GetCurrentAbsoluteTime() */
}
/* GetCurrentAbsoluteTimeUsec()
* Get the current system time. Set timezone parameters if not specified elsewhere.
* Define HasCTZSet to allow clients to specify the default timezone.
* Get the current system time.
*
* Returns the number of seconds since epoch (January 1 1970 GMT)
* Returns the number of seconds since epoch (January 1 1970 GMT),
* and returns fractional seconds (as # of microseconds) into *usec.
*/
AbsoluteTime
GetCurrentAbsoluteTimeUsec(int *usec)
@ -167,85 +109,28 @@ GetCurrentAbsoluteTimeUsec(int *usec)
time_t now;
struct timeval tp;
#ifdef NOT_USED
struct timezone tpz;
#endif
#if defined(HAVE_TM_ZONE) || defined(HAVE_INT_TIMEZONE)
struct tm *tm;
#else
struct timeb tb; /* the old V7-ism */
#endif
gettimeofday(&tp, NULL);
now = tp.tv_sec;
*usec = tp.tv_usec;
#ifdef NOT_USED
#if defined(HAVE_TM_ZONE) || defined(HAVE_INT_TIMEZONE)
now = time(NULL);
#else
ftime(&tb);
now = tb.time;
#endif
#endif
if (!HasCTZSet)
{
#if defined(HAVE_TM_ZONE)
tm = localtime(&now);
CTimeZone = -tm->tm_gmtoff; /* tm_gmtoff is Sun/DEC-ism */
CDayLight = (tm->tm_isdst > 0);
#ifdef NOT_USED
/*
* XXX is there a better way to get local timezone string w/o
* tzname? - tgl 97/03/18
*/
strftime(CTZName, MAXTZLEN, "%Z", tm);
#endif
/*
* XXX FreeBSD man pages indicate that this should work - thomas
* 1998-12-12
*/
StrNCpy(CTZName, tm->tm_zone, MAXTZLEN+1);
#elif defined(HAVE_INT_TIMEZONE)
tm = localtime(&now);
CDayLight = tm->tm_isdst;
CTimeZone = ((tm->tm_isdst > 0) ? (TIMEZONE_GLOBAL - 3600) : TIMEZONE_GLOBAL);
StrNCpy(CTZName, tzname[tm->tm_isdst], MAXTZLEN+1);
#else /* neither HAVE_TM_ZONE nor
* HAVE_INT_TIMEZONE */
CTimeZone = tb.timezone * 60;
CDayLight = (tb.dstflag != 0);
/*
* XXX does this work to get the local timezone string in V7? -
* tgl 97/03/18
*/
strftime(CTZName, MAXTZLEN, "%Z", localtime(&now));
#endif
};
return (AbsoluteTime) now;
} /* GetCurrentAbsoluteTimeUsec() */
}
/* GetCurrentDateTime()
* Get the transaction start time ("now()") broken down as a struct tm.
*/
void
GetCurrentDateTime(struct tm * tm)
{
int tz;
abstime2tm(GetCurrentTransactionStartTime(), &tz, tm, NULL);
} /* GetCurrentDateTime() */
}
/* GetCurrentTimeUsec()
* Get the transaction start time ("now()") broken down as a struct tm,
* plus fractional-second and timezone info.
*/
void
GetCurrentTimeUsec(struct tm * tm, fsec_t *fsec, int *tzp)
{
@ -253,7 +138,7 @@ GetCurrentTimeUsec(struct tm * tm, fsec_t *fsec, int *tzp)
int usec;
abstime2tm(GetCurrentTransactionStartTimeUsec(&usec), &tz, tm, NULL);
/* Note: don't pass NULL tzp directly to abstime2tm */
/* Note: don't pass NULL tzp to abstime2tm; affects behavior */
if (tzp != NULL)
*tzp = tz;
#ifdef HAVE_INT64_TIMESTAMP
@ -261,23 +146,15 @@ GetCurrentTimeUsec(struct tm * tm, fsec_t *fsec, int *tzp)
#else
*fsec = usec * 1.0e-6;
#endif
} /* GetCurrentTimeUsec() */
}
void
abstime2tm(AbsoluteTime _time, int *tzp, struct tm * tm, char **tzn)
{
time_t time = (time_t) _time;
#if defined(HAVE_TM_ZONE) || defined(HAVE_INT_TIMEZONE)
struct tm *tx;
#else
struct timeb tb; /* the old V7-ism */
ftime(&tb);
#endif
/*
* If HasCTZSet is true then we have a brute force time zone
* specified. Go ahead and rotate to the local time zone since we will
@ -286,7 +163,6 @@ abstime2tm(AbsoluteTime _time, int *tzp, struct tm * tm, char **tzn)
if (HasCTZSet && (tzp != NULL))
time -= CTimeZone;
#if defined(HAVE_TM_ZONE) || defined(HAVE_INT_TIMEZONE)
if ((!HasCTZSet) && (tzp != NULL))
tx = localtime((time_t *) &time);
else
@ -336,7 +212,8 @@ abstime2tm(AbsoluteTime _time, int *tzp, struct tm * tm, char **tzn)
*/
StrNCpy(*tzn, tm->tm_zone, MAXTZLEN + 1);
if (strlen(tm->tm_zone) > MAXTZLEN)
elog(WARNING, "Invalid timezone \'%s\'", tm->tm_zone);
elog(WARNING, "Invalid timezone \'%s\'",
tm->tm_zone);
}
}
}
@ -369,13 +246,13 @@ abstime2tm(AbsoluteTime _time, int *tzp, struct tm * tm, char **tzn)
*/
StrNCpy(*tzn, tzname[tm->tm_isdst], MAXTZLEN + 1);
if (strlen(tzname[tm->tm_isdst]) > MAXTZLEN)
elog(WARNING, "Invalid timezone \'%s\'", tzname[tm->tm_isdst]);
elog(WARNING, "Invalid timezone \'%s\'",
tzname[tm->tm_isdst]);
}
}
}
else
tm->tm_isdst = -1;
#endif
#else /* not (HAVE_TM_ZONE || HAVE_INT_TIMEZONE) */
if (tzp != NULL)
{
@ -391,26 +268,16 @@ abstime2tm(AbsoluteTime _time, int *tzp, struct tm * tm, char **tzn)
}
else
{
*tzp = tb.timezone * 60;
/*
* XXX does this work to get the local timezone string in V7?
* - tgl 97/03/18
*/
/* default to UTC */
*tzp = 0;
if (tzn != NULL)
{
strftime(*tzn, MAXTZLEN, "%Z", localtime(&now));
tzn[MAXTZLEN] = '\0'; /* let's just be sure it's
* null-terminated */
}
*tzn = NULL;
}
}
else
tm->tm_isdst = -1;
#endif
return;
} /* abstime2tm() */
}
/* tm2abstime()
@ -451,7 +318,7 @@ tm2abstime(struct tm * tm, int tz)
return INVALID_ABSTIME;
return sec;
} /* tm2abstime() */
}
/* nabstimein()
@ -888,9 +755,7 @@ reltime2tm(RelativeTime time, struct tm * tm)
TMODULO(time, tm->tm_hour, 3600);
TMODULO(time, tm->tm_min, 60);
TMODULO(time, tm->tm_sec, 1);
return;
} /* reltime2tm() */
}
/*

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/timestamp.c,v 1.77 2003/01/22 20:44:20 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/timestamp.c,v 1.78 2003/02/22 05:57:45 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -808,11 +808,13 @@ timestamp2tm(Timestamp dt, int *tzp, struct tm * tm, fsec_t *fsec, char **tzn)
* later bypass any calls which adjust the tm fields.
*/
if (HasCTZSet && (tzp != NULL))
{
#ifdef HAVE_INT64_TIMESTAMP
dt -= (CTimeZone * INT64CONST(1000000));
#else
dt -= CTimeZone;
#endif
}
time = dt;
#ifdef HAVE_INT64_TIMESTAMP
@ -908,9 +910,11 @@ timestamp2tm(Timestamp dt, int *tzp, struct tm * tm, fsec_t *fsec, char **tzn)
#endif
#else /* not (HAVE_TM_ZONE || HAVE_INT_TIMEZONE) */
*tzp = CTimeZone; /* V7 conventions; don't know timezone? */
*tzp = 0;
/* Mark this as *no* time zone available */
tm->tm_isdst = -1;
if (tzn != NULL)
*tzn = CTZName;
*tzn = NULL;
#endif
dt = dt2local(dt, *tzp);

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/init/globals.c,v 1.68 2002/10/03 17:07:53 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/init/globals.c,v 1.69 2003/02/22 05:57:45 tgl Exp $
*
* NOTES
* Globals used all over the place should be declared here and not
@ -62,9 +62,7 @@ bool IsUnderPostmaster = false;
int DateStyle = USE_ISO_DATES;
bool EuroDates = false;
bool HasCTZSet = false;
bool CDayLight = false;
int CTimeZone = 0;
char CTZName[MAXTZLEN + 1] = "";
bool enableFsync = true;
bool allowSystemTableMods = false;

View File

@ -12,7 +12,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: miscadmin.h,v 1.115 2003/01/09 18:00:24 tgl Exp $
* $Id: miscadmin.h,v 1.116 2003/02/22 05:57:45 tgl Exp $
*
* NOTES
* some of the information in this file should be moved to
@ -141,10 +141,8 @@ extern DLLIMPORT Oid MyDatabaseId;
* DateStyle specifies preference for date formatting for output.
* EuroDates if client prefers dates interpreted and written w/European conventions.
*
* HasCTZSet if client timezone is specified by client.
* CDayLight is the apparent daylight savings time status.
* CTimeZone is the timezone offset in seconds.
* CTZName is the timezone label.
* HasCTZSet is true if user has set timezone as a numeric offset from UTC.
* If so, CTimeZone is the timezone offset in seconds.
*/
#define MAXTZLEN 10 /* max TZ name len, not counting tr. null */
@ -157,9 +155,7 @@ extern DLLIMPORT Oid MyDatabaseId;
extern int DateStyle;
extern bool EuroDates;
extern bool HasCTZSet;
extern bool CDayLight;
extern int CTimeZone;
extern char CTZName[];
extern bool enableFsync;
extern bool allowSystemTableMods;