Skip to content

Commit 921d749

Browse files
committed
Adjust our timezone library to use pg_time_t (typedef'd as int64) in
place of time_t, as per prior discussion. The behavior does not change on machines without a 64-bit-int type, but on machines with one, which is most, we are rid of the bizarre boundary behavior at the edges of the 32-bit-time_t range (1901 and 2038). The system will now treat times over the full supported timestamp range as being in your local time zone. It may seem a little bizarre to consider that times in 4000 BC are PST or EST, but this is surely at least as reasonable as propagating Gregorian calendar rules back that far. I did not modify the format of the zic timezone database files, which means that for the moment the system will not know about daylight-savings periods outside the range 1901-2038. Given the way the files are set up, it's not a simple decision like 'widen to 64 bits'; we have to actually think about the range of years that need to be supported. We should probably inquire what the plans of the upstream zic people are before making any decisions of our own.
1 parent 473ac70 commit 921d749

File tree

28 files changed

+418
-785
lines changed

28 files changed

+418
-785
lines changed

src/backend/access/transam/xact.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.167 2004/05/22 23:14:37 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.168 2004/06/03 02:08:00 tgl Exp $
1212
*
1313
* NOTES
1414
* Transaction aborts can now occur two ways:
@@ -141,6 +141,7 @@
141141

142142
#include "postgres.h"
143143

144+
#include <time.h>
144145
#include <unistd.h>
145146

146147
#include "access/gistscan.h"
@@ -1858,7 +1859,7 @@ xact_desc(char *buf, uint8 xl_info, char *rec)
18581859
if (info == XLOG_XACT_COMMIT)
18591860
{
18601861
xl_xact_commit *xlrec = (xl_xact_commit *) rec;
1861-
struct pg_tm *tm = pg_localtime(&xlrec->xtime);
1862+
struct tm *tm = localtime(&xlrec->xtime);
18621863

18631864
sprintf(buf + strlen(buf), "commit: %04u-%02u-%02u %02u:%02u:%02u",
18641865
tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
@@ -1868,7 +1869,7 @@ xact_desc(char *buf, uint8 xl_info, char *rec)
18681869
else if (info == XLOG_XACT_ABORT)
18691870
{
18701871
xl_xact_abort *xlrec = (xl_xact_abort *) rec;
1871-
struct pg_tm *tm = pg_localtime(&xlrec->xtime);
1872+
struct tm *tm = localtime(&xlrec->xtime);
18721873

18731874
sprintf(buf + strlen(buf), "abort: %04u-%02u-%02u %02u:%02u:%02u",
18741875
tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,

src/backend/access/transam/xlog.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.145 2004/05/29 22:48:18 tgl Exp $
10+
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.146 2004/06/03 02:08:00 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -16,6 +16,7 @@
1616

1717
#include <fcntl.h>
1818
#include <signal.h>
19+
#include <time.h>
1920
#include <unistd.h>
2021
#include <sys/stat.h>
2122
#include <sys/time.h>
@@ -2761,9 +2762,9 @@ str_time(time_t tnow)
27612762
{
27622763
static char buf[128];
27632764

2764-
pg_strftime(buf, sizeof(buf),
2765+
strftime(buf, sizeof(buf),
27652766
"%Y-%m-%d %H:%M:%S %Z",
2766-
pg_localtime(&tnow));
2767+
localtime(&tnow));
27672768

27682769
return buf;
27692770
}

src/backend/bootstrap/bootparse.y

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/bootstrap/bootparse.y,v 1.68 2004/05/26 04:41:05 neilc Exp $
12+
* $PostgreSQL: pgsql/src/backend/bootstrap/bootparse.y,v 1.69 2004/06/03 02:08:02 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -38,7 +38,6 @@
3838
#include "nodes/parsenodes.h"
3939
#include "nodes/pg_list.h"
4040
#include "nodes/primnodes.h"
41-
#include "pgtime.h"
4241
#include "rewrite/prs2lock.h"
4342
#include "storage/block.h"
4443
#include "storage/fd.h"

src/backend/bootstrap/bootscanner.l

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/bootstrap/bootscanner.l,v 1.34 2004/05/21 05:07:56 tgl Exp $
12+
* $PostgreSQL: pgsql/src/backend/bootstrap/bootscanner.l,v 1.35 2004/06/03 02:08:02 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -29,7 +29,6 @@
2929
#include "nodes/pg_list.h"
3030
#include "nodes/primnodes.h"
3131
#include "parser/scansup.h"
32-
#include "pgtime.h"
3332
#include "rewrite/prs2lock.h"
3433
#include "storage/block.h"
3534
#include "storage/fd.h"

src/backend/bootstrap/bootstrap.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/bootstrap/bootstrap.c,v 1.182 2004/05/29 22:48:18 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/bootstrap/bootstrap.c,v 1.183 2004/06/03 02:08:02 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -34,7 +34,6 @@
3434
#include "libpq/pqsignal.h"
3535
#include "miscadmin.h"
3636
#include "postmaster/bgwriter.h"
37-
#include "pgtime.h"
3837
#include "storage/freespace.h"
3938
#include "storage/ipc.h"
4039
#include "storage/pg_shmem.h"

src/backend/optimizer/geqo/geqo_main.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/backend/optimizer/geqo/geqo_main.c,v 1.44 2004/05/21 05:07:57 tgl Exp $
10+
* $PostgreSQL: pgsql/src/backend/optimizer/geqo/geqo_main.c,v 1.45 2004/06/03 02:08:02 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -31,7 +31,6 @@
3131
#include "optimizer/geqo_mutation.h"
3232
#include "optimizer/geqo_pool.h"
3333
#include "optimizer/geqo_selection.h"
34-
#include "pgtime.h"
3534

3635

3736
/*

src/backend/postmaster/bgwriter.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,14 @@
3737
*
3838
*
3939
* IDENTIFICATION
40-
* $PostgreSQL: pgsql/src/backend/postmaster/bgwriter.c,v 1.2 2004/05/31 03:47:59 tgl Exp $
40+
* $PostgreSQL: pgsql/src/backend/postmaster/bgwriter.c,v 1.3 2004/06/03 02:08:03 tgl Exp $
4141
*
4242
*-------------------------------------------------------------------------
4343
*/
4444
#include "postgres.h"
4545

4646
#include <signal.h>
47+
#include <time.h>
4748

4849
#include "access/xlog.h"
4950
#include "libpq/pqsignal.h"

src/backend/postmaster/pgstat.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
* Copyright (c) 2001-2003, PostgreSQL Global Development Group
1515
*
16-
* $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.73 2004/05/29 22:48:19 tgl Exp $
16+
* $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.74 2004/06/03 02:08:03 tgl Exp $
1717
* ----------
1818
*/
1919
#include "postgres.h"
@@ -29,6 +29,7 @@
2929
#include <arpa/inet.h>
3030
#include <errno.h>
3131
#include <signal.h>
32+
#include <time.h>
3233

3334
#include "pgstat.h"
3435

src/backend/postmaster/postmaster.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*
3838
*
3939
* IDENTIFICATION
40-
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.401 2004/05/30 03:50:11 tgl Exp $
40+
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.402 2004/06/03 02:08:03 tgl Exp $
4141
*
4242
* NOTES
4343
*
@@ -62,6 +62,7 @@
6262

6363
#include <unistd.h>
6464
#include <signal.h>
65+
#include <time.h>
6566
#include <sys/wait.h>
6667
#include <ctype.h>
6768
#include <sys/stat.h>
@@ -97,7 +98,6 @@
9798
#include "miscadmin.h"
9899
#include "nodes/nodes.h"
99100
#include "postmaster/postmaster.h"
100-
#include "pgtime.h"
101101
#include "storage/fd.h"
102102
#include "storage/ipc.h"
103103
#include "storage/pg_shmem.h"

src/backend/storage/buffer/freelist.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@
1212
*
1313
*
1414
* IDENTIFICATION
15-
* $PostgreSQL: pgsql/src/backend/storage/buffer/freelist.c,v 1.43 2004/04/21 18:06:30 tgl Exp $
15+
* $PostgreSQL: pgsql/src/backend/storage/buffer/freelist.c,v 1.44 2004/06/03 02:08:03 tgl Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
1919
#include "postgres.h"
2020

21+
#include <time.h>
22+
2123
#include "access/xact.h"
2224
#include "storage/buf_internals.h"
2325
#include "storage/bufmgr.h"

src/backend/tcop/postgres.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.417 2004/05/29 22:48:20 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.418 2004/06/03 02:08:03 tgl Exp $
1212
*
1313
* NOTES
1414
* this is the "main" module of the postgres backend and
@@ -46,7 +46,6 @@
4646
#include "optimizer/planner.h"
4747
#include "parser/analyze.h"
4848
#include "parser/parser.h"
49-
#include "pgtime.h"
5049
#include "rewrite/rewriteHandler.h"
5150
#include "storage/freespace.h"
5251
#include "storage/ipc.h"

src/backend/utils/adt/date.c

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/adt/date.c,v 1.98 2004/05/31 18:53:17 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/date.c,v 1.99 2004/06/03 02:08:04 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -23,7 +23,6 @@
2323
#include "libpq/pqformat.h"
2424
#include "miscadmin.h"
2525
#include "parser/scansup.h"
26-
#include "pgtime.h"
2726
#include "utils/builtins.h"
2827
#include "utils/date.h"
2928
#include "utils/nabstime.h"
@@ -295,35 +294,22 @@ date2timestamptz(DateADT dateVal)
295294
TimestampTz result;
296295
struct pg_tm tt,
297296
*tm = &tt;
297+
int tz;
298298

299299
j2date(dateVal + POSTGRES_EPOCH_JDATE,
300300
&(tm->tm_year), &(tm->tm_mon), &(tm->tm_mday));
301301

302-
if (IS_VALID_UTIME(tm->tm_year, tm->tm_mon, tm->tm_mday))
303-
{
304-
int tz;
305-
306-
tm->tm_hour = 0;
307-
tm->tm_min = 0;
308-
tm->tm_sec = 0;
309-
tz = DetermineLocalTimeZone(tm);
302+
tm->tm_hour = 0;
303+
tm->tm_min = 0;
304+
tm->tm_sec = 0;
305+
tz = DetermineLocalTimeZone(tm);
310306

311307
#ifdef HAVE_INT64_TIMESTAMP
312-
result = (dateVal * INT64CONST(86400000000))
313-
+ (tz * INT64CONST(1000000));
314-
#else
315-
result = dateVal * 86400.0 + tz;
316-
#endif
317-
}
318-
else
319-
{
320-
/* Outside of range for timezone support, so assume UTC */
321-
#ifdef HAVE_INT64_TIMESTAMP
322-
result = (dateVal * INT64CONST(86400000000));
308+
result = (dateVal * INT64CONST(86400000000))
309+
+ (tz * INT64CONST(1000000));
323310
#else
324-
result = dateVal * 86400.0;
311+
result = dateVal * 86400.0 + tz;
325312
#endif
326-
}
327313

328314
return result;
329315
}

0 commit comments

Comments
 (0)