Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 80d6a27

Browse files
committed
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.
1 parent 799bc58 commit 80d6a27

File tree

5 files changed

+43
-179
lines changed

5 files changed

+43
-179
lines changed

src/backend/utils/adt/datetime.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/datetime.c,v 1.101 2003/02/20 05:24:55 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/datetime.c,v 1.102 2003/02/22 05:57:44 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1604,8 +1604,9 @@ DetermineLocalTimeZone(struct tm * tm)
16041604
tz = (int) delta2;
16051605
}
16061606
#else /* not (HAVE_TM_ZONE || HAVE_INT_TIMEZONE) */
1607+
/* Assume UTC if no system timezone info available */
16071608
tm->tm_isdst = 0;
1608-
tz = CTimeZone;
1609+
tz = 0;
16091610
#endif
16101611
}
16111612
else

src/backend/utils/adt/nabstime.c

+29-164
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/*-------------------------------------------------------------------------
2+
*
23
* nabstime.c
34
* Utilities for the built-in type "AbsoluteTime".
45
* Functions for the built-in type "RelativeTime".
@@ -9,9 +10,7 @@
910
*
1011
*
1112
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/nabstime.c,v 1.103 2003/02/20 05:24:55 tgl Exp $
13-
*
14-
* NOTES
13+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/nabstime.c,v 1.104 2003/02/22 05:57:45 tgl Exp $
1514
*
1615
*-------------------------------------------------------------------------
1716
*/
@@ -23,10 +22,6 @@
2322
#include <float.h>
2423
#include <limits.h>
2524

26-
#if !(defined(HAVE_TM_ZONE) || defined(HAVE_INT_TIMEZONE))
27-
#include <sys/timeb.h>
28-
#endif
29-
3025
#include "access/xact.h"
3126
#include "miscadmin.h"
3227
#include "utils/builtins.h"
@@ -88,196 +83,78 @@ static int istinterval(char *i_string,
8883

8984

9085
/* GetCurrentAbsoluteTime()
91-
* Get the current system time. Set timezone parameters if not specified elsewhere.
92-
* Define HasCTZSet to allow clients to specify the default timezone.
86+
* Get the current system time.
9387
*
94-
* Returns the number of seconds since epoch (January 1 1970 GMT)
88+
* Returns the number of seconds since epoch (January 1 1970 GMT).
9589
*/
9690
AbsoluteTime
9791
GetCurrentAbsoluteTime(void)
9892
{
9993
time_t now;
10094

101-
#if defined(HAVE_TM_ZONE) || defined(HAVE_INT_TIMEZONE)
102-
struct tm *tm;
103-
10495
now = time(NULL);
105-
#else
106-
struct timeb tb; /* the old V7-ism */
107-
108-
ftime(&tb);
109-
now = tb.time;
110-
#endif
111-
112-
if (!HasCTZSet)
113-
{
114-
#if defined(HAVE_TM_ZONE)
115-
tm = localtime(&now);
116-
117-
CTimeZone = -tm->tm_gmtoff; /* tm_gmtoff is Sun/DEC-ism */
118-
CDayLight = (tm->tm_isdst > 0);
119-
120-
#ifdef NOT_USED
121-
122-
/*
123-
* XXX is there a better way to get local timezone string w/o
124-
* tzname? - tgl 97/03/18
125-
*/
126-
strftime(CTZName, MAXTZLEN, "%Z", tm);
127-
#endif
128-
129-
/*
130-
* XXX FreeBSD man pages indicate that this should work - thomas
131-
* 1998-12-12
132-
*/
133-
StrNCpy(CTZName, tm->tm_zone, MAXTZLEN+1);
134-
135-
#elif defined(HAVE_INT_TIMEZONE)
136-
tm = localtime(&now);
137-
138-
CDayLight = tm->tm_isdst;
139-
CTimeZone = ((tm->tm_isdst > 0) ? (TIMEZONE_GLOBAL - 3600) : TIMEZONE_GLOBAL);
140-
StrNCpy(CTZName, tzname[tm->tm_isdst], MAXTZLEN+1);
141-
#else /* neither HAVE_TM_ZONE nor
142-
* HAVE_INT_TIMEZONE */
143-
CTimeZone = tb.timezone * 60;
144-
CDayLight = (tb.dstflag != 0);
145-
146-
/*
147-
* XXX does this work to get the local timezone string in V7? -
148-
* tgl 97/03/18
149-
*/
150-
strftime(CTZName, MAXTZLEN, "%Z", localtime(&now));
151-
#endif
152-
}
153-
15496
return (AbsoluteTime) now;
155-
} /* GetCurrentAbsoluteTime() */
97+
}
15698

15799

158100
/* GetCurrentAbsoluteTimeUsec()
159-
* Get the current system time. Set timezone parameters if not specified elsewhere.
160-
* Define HasCTZSet to allow clients to specify the default timezone.
101+
* Get the current system time.
161102
*
162-
* Returns the number of seconds since epoch (January 1 1970 GMT)
103+
* Returns the number of seconds since epoch (January 1 1970 GMT),
104+
* and returns fractional seconds (as # of microseconds) into *usec.
163105
*/
164106
AbsoluteTime
165107
GetCurrentAbsoluteTimeUsec(int *usec)
166108
{
167109
time_t now;
168110
struct timeval tp;
169111

170-
#ifdef NOT_USED
171-
struct timezone tpz;
172-
#endif
173-
#if defined(HAVE_TM_ZONE) || defined(HAVE_INT_TIMEZONE)
174-
struct tm *tm;
175-
176-
#else
177-
struct timeb tb; /* the old V7-ism */
178-
#endif
179-
180112
gettimeofday(&tp, NULL);
181-
182113
now = tp.tv_sec;
183114
*usec = tp.tv_usec;
184-
185-
#ifdef NOT_USED
186-
#if defined(HAVE_TM_ZONE) || defined(HAVE_INT_TIMEZONE)
187-
now = time(NULL);
188-
#else
189-
ftime(&tb);
190-
now = tb.time;
191-
#endif
192-
#endif
193-
194-
if (!HasCTZSet)
195-
{
196-
#if defined(HAVE_TM_ZONE)
197-
tm = localtime(&now);
198-
199-
CTimeZone = -tm->tm_gmtoff; /* tm_gmtoff is Sun/DEC-ism */
200-
CDayLight = (tm->tm_isdst > 0);
201-
202-
#ifdef NOT_USED
203-
204-
/*
205-
* XXX is there a better way to get local timezone string w/o
206-
* tzname? - tgl 97/03/18
207-
*/
208-
strftime(CTZName, MAXTZLEN, "%Z", tm);
209-
#endif
210-
211-
/*
212-
* XXX FreeBSD man pages indicate that this should work - thomas
213-
* 1998-12-12
214-
*/
215-
StrNCpy(CTZName, tm->tm_zone, MAXTZLEN+1);
216-
217-
#elif defined(HAVE_INT_TIMEZONE)
218-
tm = localtime(&now);
219-
220-
CDayLight = tm->tm_isdst;
221-
CTimeZone = ((tm->tm_isdst > 0) ? (TIMEZONE_GLOBAL - 3600) : TIMEZONE_GLOBAL);
222-
StrNCpy(CTZName, tzname[tm->tm_isdst], MAXTZLEN+1);
223-
#else /* neither HAVE_TM_ZONE nor
224-
* HAVE_INT_TIMEZONE */
225-
CTimeZone = tb.timezone * 60;
226-
CDayLight = (tb.dstflag != 0);
227-
228-
/*
229-
* XXX does this work to get the local timezone string in V7? -
230-
* tgl 97/03/18
231-
*/
232-
strftime(CTZName, MAXTZLEN, "%Z", localtime(&now));
233-
#endif
234-
};
235-
236115
return (AbsoluteTime) now;
237-
} /* GetCurrentAbsoluteTimeUsec() */
116+
}
238117

239118

119+
/* GetCurrentDateTime()
120+
* Get the transaction start time ("now()") broken down as a struct tm.
121+
*/
240122
void
241123
GetCurrentDateTime(struct tm * tm)
242124
{
243125
int tz;
244126

245127
abstime2tm(GetCurrentTransactionStartTime(), &tz, tm, NULL);
246-
} /* GetCurrentDateTime() */
247-
128+
}
248129

130+
/* GetCurrentTimeUsec()
131+
* Get the transaction start time ("now()") broken down as a struct tm,
132+
* plus fractional-second and timezone info.
133+
*/
249134
void
250135
GetCurrentTimeUsec(struct tm * tm, fsec_t *fsec, int *tzp)
251136
{
252137
int tz;
253138
int usec;
254139

255140
abstime2tm(GetCurrentTransactionStartTimeUsec(&usec), &tz, tm, NULL);
256-
/* Note: don't pass NULL tzp directly to abstime2tm */
141+
/* Note: don't pass NULL tzp to abstime2tm; affects behavior */
257142
if (tzp != NULL)
258143
*tzp = tz;
259144
#ifdef HAVE_INT64_TIMESTAMP
260145
*fsec = usec;
261146
#else
262147
*fsec = usec * 1.0e-6;
263148
#endif
264-
} /* GetCurrentTimeUsec() */
149+
}
265150

266151

267152
void
268153
abstime2tm(AbsoluteTime _time, int *tzp, struct tm * tm, char **tzn)
269154
{
270155
time_t time = (time_t) _time;
271-
272-
#if defined(HAVE_TM_ZONE) || defined(HAVE_INT_TIMEZONE)
273156
struct tm *tx;
274157

275-
#else
276-
struct timeb tb; /* the old V7-ism */
277-
278-
ftime(&tb);
279-
#endif
280-
281158
/*
282159
* If HasCTZSet is true then we have a brute force time zone
283160
* 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)
286163
if (HasCTZSet && (tzp != NULL))
287164
time -= CTimeZone;
288165

289-
#if defined(HAVE_TM_ZONE) || defined(HAVE_INT_TIMEZONE)
290166
if ((!HasCTZSet) && (tzp != NULL))
291167
tx = localtime((time_t *) &time);
292168
else
@@ -336,7 +212,8 @@ abstime2tm(AbsoluteTime _time, int *tzp, struct tm * tm, char **tzn)
336212
*/
337213
StrNCpy(*tzn, tm->tm_zone, MAXTZLEN + 1);
338214
if (strlen(tm->tm_zone) > MAXTZLEN)
339-
elog(WARNING, "Invalid timezone \'%s\'", tm->tm_zone);
215+
elog(WARNING, "Invalid timezone \'%s\'",
216+
tm->tm_zone);
340217
}
341218
}
342219
}
@@ -369,13 +246,13 @@ abstime2tm(AbsoluteTime _time, int *tzp, struct tm * tm, char **tzn)
369246
*/
370247
StrNCpy(*tzn, tzname[tm->tm_isdst], MAXTZLEN + 1);
371248
if (strlen(tzname[tm->tm_isdst]) > MAXTZLEN)
372-
elog(WARNING, "Invalid timezone \'%s\'", tzname[tm->tm_isdst]);
249+
elog(WARNING, "Invalid timezone \'%s\'",
250+
tzname[tm->tm_isdst]);
373251
}
374252
}
375253
}
376254
else
377255
tm->tm_isdst = -1;
378-
#endif
379256
#else /* not (HAVE_TM_ZONE || HAVE_INT_TIMEZONE) */
380257
if (tzp != NULL)
381258
{
@@ -391,26 +268,16 @@ abstime2tm(AbsoluteTime _time, int *tzp, struct tm * tm, char **tzn)
391268
}
392269
else
393270
{
394-
*tzp = tb.timezone * 60;
395-
396-
/*
397-
* XXX does this work to get the local timezone string in V7?
398-
* - tgl 97/03/18
399-
*/
271+
/* default to UTC */
272+
*tzp = 0;
400273
if (tzn != NULL)
401-
{
402-
strftime(*tzn, MAXTZLEN, "%Z", localtime(&now));
403-
tzn[MAXTZLEN] = '\0'; /* let's just be sure it's
404-
* null-terminated */
405-
}
274+
*tzn = NULL;
406275
}
407276
}
408277
else
409278
tm->tm_isdst = -1;
410279
#endif
411-
412-
return;
413-
} /* abstime2tm() */
280+
}
414281

415282

416283
/* tm2abstime()
@@ -451,7 +318,7 @@ tm2abstime(struct tm * tm, int tz)
451318
return INVALID_ABSTIME;
452319

453320
return sec;
454-
} /* tm2abstime() */
321+
}
455322

456323

457324
/* nabstimein()
@@ -888,9 +755,7 @@ reltime2tm(RelativeTime time, struct tm * tm)
888755
TMODULO(time, tm->tm_hour, 3600);
889756
TMODULO(time, tm->tm_min, 60);
890757
TMODULO(time, tm->tm_sec, 1);
891-
892-
return;
893-
} /* reltime2tm() */
758+
}
894759

895760

896761
/*

src/backend/utils/adt/timestamp.c

+7-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/timestamp.c,v 1.77 2003/01/22 20:44:20 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/timestamp.c,v 1.78 2003/02/22 05:57:45 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -808,11 +808,13 @@ timestamp2tm(Timestamp dt, int *tzp, struct tm * tm, fsec_t *fsec, char **tzn)
808808
* later bypass any calls which adjust the tm fields.
809809
*/
810810
if (HasCTZSet && (tzp != NULL))
811+
{
811812
#ifdef HAVE_INT64_TIMESTAMP
812813
dt -= (CTimeZone * INT64CONST(1000000));
813814
#else
814815
dt -= CTimeZone;
815816
#endif
817+
}
816818

817819
time = dt;
818820
#ifdef HAVE_INT64_TIMESTAMP
@@ -908,9 +910,11 @@ timestamp2tm(Timestamp dt, int *tzp, struct tm * tm, fsec_t *fsec, char **tzn)
908910
#endif
909911

910912
#else /* not (HAVE_TM_ZONE || HAVE_INT_TIMEZONE) */
911-
*tzp = CTimeZone; /* V7 conventions; don't know timezone? */
913+
*tzp = 0;
914+
/* Mark this as *no* time zone available */
915+
tm->tm_isdst = -1;
912916
if (tzn != NULL)
913-
*tzn = CTZName;
917+
*tzn = NULL;
914918
#endif
915919

916920
dt = dt2local(dt, *tzp);

0 commit comments

Comments
 (0)