Commit 80d6a277 authored by Tom Lane's avatar Tom Lane

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.
parent 799bc58d
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * 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) ...@@ -1604,8 +1604,9 @@ DetermineLocalTimeZone(struct tm * tm)
tz = (int) delta2; tz = (int) delta2;
} }
#else /* not (HAVE_TM_ZONE || HAVE_INT_TIMEZONE) */ #else /* not (HAVE_TM_ZONE || HAVE_INT_TIMEZONE) */
/* Assume UTC if no system timezone info available */
tm->tm_isdst = 0; tm->tm_isdst = 0;
tz = CTimeZone; tz = 0;
#endif #endif
} }
else else
......
/*------------------------------------------------------------------------- /*-------------------------------------------------------------------------
*
* nabstime.c * nabstime.c
* Utilities for the built-in type "AbsoluteTime". * Utilities for the built-in type "AbsoluteTime".
* Functions for the built-in type "RelativeTime". * Functions for the built-in type "RelativeTime".
...@@ -9,9 +10,7 @@ ...@@ -9,9 +10,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/nabstime.c,v 1.103 2003/02/20 05:24:55 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/nabstime.c,v 1.104 2003/02/22 05:57:45 tgl Exp $
*
* NOTES
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -23,10 +22,6 @@ ...@@ -23,10 +22,6 @@
#include <float.h> #include <float.h>
#include <limits.h> #include <limits.h>
#if !(defined(HAVE_TM_ZONE) || defined(HAVE_INT_TIMEZONE))
#include <sys/timeb.h>
#endif
#include "access/xact.h" #include "access/xact.h"
#include "miscadmin.h" #include "miscadmin.h"
#include "utils/builtins.h" #include "utils/builtins.h"
...@@ -88,78 +83,25 @@ static int istinterval(char *i_string, ...@@ -88,78 +83,25 @@ static int istinterval(char *i_string,
/* GetCurrentAbsoluteTime() /* GetCurrentAbsoluteTime()
* Get the current system time. Set timezone parameters if not specified elsewhere. * Get the current system time.
* Define HasCTZSet to allow clients to specify the default timezone.
* *
* Returns the number of seconds since epoch (January 1 1970 GMT) * Returns the number of seconds since epoch (January 1 1970 GMT).
*/ */
AbsoluteTime AbsoluteTime
GetCurrentAbsoluteTime(void) GetCurrentAbsoluteTime(void)
{ {
time_t now; time_t now;
#if defined(HAVE_TM_ZONE) || defined(HAVE_INT_TIMEZONE)
struct tm *tm;
now = time(NULL); 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; return (AbsoluteTime) now;
} /* GetCurrentAbsoluteTime() */ }
/* GetCurrentAbsoluteTimeUsec() /* GetCurrentAbsoluteTimeUsec()
* Get the current system time. Set timezone parameters if not specified elsewhere. * Get the current system time.
* Define HasCTZSet to allow clients to specify the default timezone.
* *
* 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 AbsoluteTime
GetCurrentAbsoluteTimeUsec(int *usec) GetCurrentAbsoluteTimeUsec(int *usec)
...@@ -167,85 +109,28 @@ GetCurrentAbsoluteTimeUsec(int *usec) ...@@ -167,85 +109,28 @@ GetCurrentAbsoluteTimeUsec(int *usec)
time_t now; time_t now;
struct timeval tp; 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); gettimeofday(&tp, NULL);
now = tp.tv_sec; now = tp.tv_sec;
*usec = tp.tv_usec; *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; return (AbsoluteTime) now;
} /* GetCurrentAbsoluteTimeUsec() */ }
/* GetCurrentDateTime()
* Get the transaction start time ("now()") broken down as a struct tm.
*/
void void
GetCurrentDateTime(struct tm * tm) GetCurrentDateTime(struct tm * tm)
{ {
int tz; int tz;
abstime2tm(GetCurrentTransactionStartTime(), &tz, tm, NULL); 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 void
GetCurrentTimeUsec(struct tm * tm, fsec_t *fsec, int *tzp) GetCurrentTimeUsec(struct tm * tm, fsec_t *fsec, int *tzp)
{ {
...@@ -253,7 +138,7 @@ GetCurrentTimeUsec(struct tm * tm, fsec_t *fsec, int *tzp) ...@@ -253,7 +138,7 @@ GetCurrentTimeUsec(struct tm * tm, fsec_t *fsec, int *tzp)
int usec; int usec;
abstime2tm(GetCurrentTransactionStartTimeUsec(&usec), &tz, tm, NULL); 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) if (tzp != NULL)
*tzp = tz; *tzp = tz;
#ifdef HAVE_INT64_TIMESTAMP #ifdef HAVE_INT64_TIMESTAMP
...@@ -261,23 +146,15 @@ GetCurrentTimeUsec(struct tm * tm, fsec_t *fsec, int *tzp) ...@@ -261,23 +146,15 @@ GetCurrentTimeUsec(struct tm * tm, fsec_t *fsec, int *tzp)
#else #else
*fsec = usec * 1.0e-6; *fsec = usec * 1.0e-6;
#endif #endif
} /* GetCurrentTimeUsec() */ }
void void
abstime2tm(AbsoluteTime _time, int *tzp, struct tm * tm, char **tzn) abstime2tm(AbsoluteTime _time, int *tzp, struct tm * tm, char **tzn)
{ {
time_t time = (time_t) _time; time_t time = (time_t) _time;
#if defined(HAVE_TM_ZONE) || defined(HAVE_INT_TIMEZONE)
struct tm *tx; 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 * 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 * 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) ...@@ -286,7 +163,6 @@ abstime2tm(AbsoluteTime _time, int *tzp, struct tm * tm, char **tzn)
if (HasCTZSet && (tzp != NULL)) if (HasCTZSet && (tzp != NULL))
time -= CTimeZone; time -= CTimeZone;
#if defined(HAVE_TM_ZONE) || defined(HAVE_INT_TIMEZONE)
if ((!HasCTZSet) && (tzp != NULL)) if ((!HasCTZSet) && (tzp != NULL))
tx = localtime((time_t *) &time); tx = localtime((time_t *) &time);
else else
...@@ -336,7 +212,8 @@ abstime2tm(AbsoluteTime _time, int *tzp, struct tm * tm, char **tzn) ...@@ -336,7 +212,8 @@ abstime2tm(AbsoluteTime _time, int *tzp, struct tm * tm, char **tzn)
*/ */
StrNCpy(*tzn, tm->tm_zone, MAXTZLEN + 1); StrNCpy(*tzn, tm->tm_zone, MAXTZLEN + 1);
if (strlen(tm->tm_zone) > MAXTZLEN) 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) ...@@ -369,13 +246,13 @@ abstime2tm(AbsoluteTime _time, int *tzp, struct tm * tm, char **tzn)
*/ */
StrNCpy(*tzn, tzname[tm->tm_isdst], MAXTZLEN + 1); StrNCpy(*tzn, tzname[tm->tm_isdst], MAXTZLEN + 1);
if (strlen(tzname[tm->tm_isdst]) > MAXTZLEN) 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 else
tm->tm_isdst = -1; tm->tm_isdst = -1;
#endif
#else /* not (HAVE_TM_ZONE || HAVE_INT_TIMEZONE) */ #else /* not (HAVE_TM_ZONE || HAVE_INT_TIMEZONE) */
if (tzp != NULL) if (tzp != NULL)
{ {
...@@ -391,26 +268,16 @@ abstime2tm(AbsoluteTime _time, int *tzp, struct tm * tm, char **tzn) ...@@ -391,26 +268,16 @@ abstime2tm(AbsoluteTime _time, int *tzp, struct tm * tm, char **tzn)
} }
else else
{ {
*tzp = tb.timezone * 60; /* default to UTC */
*tzp = 0;
/*
* XXX does this work to get the local timezone string in V7?
* - tgl 97/03/18
*/
if (tzn != NULL) if (tzn != NULL)
{ *tzn = NULL;
strftime(*tzn, MAXTZLEN, "%Z", localtime(&now));
tzn[MAXTZLEN] = '\0'; /* let's just be sure it's
* null-terminated */
}
} }
} }
else else
tm->tm_isdst = -1; tm->tm_isdst = -1;
#endif #endif
}
return;
} /* abstime2tm() */
/* tm2abstime() /* tm2abstime()
...@@ -451,7 +318,7 @@ tm2abstime(struct tm * tm, int tz) ...@@ -451,7 +318,7 @@ tm2abstime(struct tm * tm, int tz)
return INVALID_ABSTIME; return INVALID_ABSTIME;
return sec; return sec;
} /* tm2abstime() */ }
/* nabstimein() /* nabstimein()
...@@ -888,9 +755,7 @@ reltime2tm(RelativeTime time, struct tm * tm) ...@@ -888,9 +755,7 @@ reltime2tm(RelativeTime time, struct tm * tm)
TMODULO(time, tm->tm_hour, 3600); TMODULO(time, tm->tm_hour, 3600);
TMODULO(time, tm->tm_min, 60); TMODULO(time, tm->tm_min, 60);
TMODULO(time, tm->tm_sec, 1); TMODULO(time, tm->tm_sec, 1);
}
return;
} /* reltime2tm() */
/* /*
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * 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) ...@@ -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. * later bypass any calls which adjust the tm fields.
*/ */
if (HasCTZSet && (tzp != NULL)) if (HasCTZSet && (tzp != NULL))
{
#ifdef HAVE_INT64_TIMESTAMP #ifdef HAVE_INT64_TIMESTAMP
dt -= (CTimeZone * INT64CONST(1000000)); dt -= (CTimeZone * INT64CONST(1000000));
#else #else
dt -= CTimeZone; dt -= CTimeZone;
#endif #endif
}
time = dt; time = dt;
#ifdef HAVE_INT64_TIMESTAMP #ifdef HAVE_INT64_TIMESTAMP
...@@ -908,9 +910,11 @@ timestamp2tm(Timestamp dt, int *tzp, struct tm * tm, fsec_t *fsec, char **tzn) ...@@ -908,9 +910,11 @@ timestamp2tm(Timestamp dt, int *tzp, struct tm * tm, fsec_t *fsec, char **tzn)
#endif #endif
#else /* not (HAVE_TM_ZONE || HAVE_INT_TIMEZONE) */ #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) if (tzn != NULL)
*tzn = CTZName; *tzn = NULL;
#endif #endif
dt = dt2local(dt, *tzp); dt = dt2local(dt, *tzp);
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * 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 * NOTES
* Globals used all over the place should be declared here and not * Globals used all over the place should be declared here and not
...@@ -62,9 +62,7 @@ bool IsUnderPostmaster = false; ...@@ -62,9 +62,7 @@ bool IsUnderPostmaster = false;
int DateStyle = USE_ISO_DATES; int DateStyle = USE_ISO_DATES;
bool EuroDates = false; bool EuroDates = false;
bool HasCTZSet = false; bool HasCTZSet = false;
bool CDayLight = false;
int CTimeZone = 0; int CTimeZone = 0;
char CTZName[MAXTZLEN + 1] = "";
bool enableFsync = true; bool enableFsync = true;
bool allowSystemTableMods = false; bool allowSystemTableMods = false;
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * 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 * NOTES
* some of the information in this file should be moved to * some of the information in this file should be moved to
...@@ -141,10 +141,8 @@ extern DLLIMPORT Oid MyDatabaseId; ...@@ -141,10 +141,8 @@ extern DLLIMPORT Oid MyDatabaseId;
* DateStyle specifies preference for date formatting for output. * DateStyle specifies preference for date formatting for output.
* EuroDates if client prefers dates interpreted and written w/European conventions. * EuroDates if client prefers dates interpreted and written w/European conventions.
* *
* HasCTZSet if client timezone is specified by client. * HasCTZSet is true if user has set timezone as a numeric offset from UTC.
* CDayLight is the apparent daylight savings time status. * If so, CTimeZone is the timezone offset in seconds.
* CTimeZone is the timezone offset in seconds.
* CTZName is the timezone label.
*/ */
#define MAXTZLEN 10 /* max TZ name len, not counting tr. null */ #define MAXTZLEN 10 /* max TZ name len, not counting tr. null */
...@@ -157,9 +155,7 @@ extern DLLIMPORT Oid MyDatabaseId; ...@@ -157,9 +155,7 @@ extern DLLIMPORT Oid MyDatabaseId;
extern int DateStyle; extern int DateStyle;
extern bool EuroDates; extern bool EuroDates;
extern bool HasCTZSet; extern bool HasCTZSet;
extern bool CDayLight;
extern int CTimeZone; extern int CTimeZone;
extern char CTZName[];
extern bool enableFsync; extern bool enableFsync;
extern bool allowSystemTableMods; extern bool allowSystemTableMods;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment