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

Commit 7dac778

Browse files
committed
Add GUC setting for Australian timezones. Uses new GUC boolean callback
functions to clear date cache. Allow regression tests to pass when timezone set.
1 parent 49ce6ff commit 7dac778

File tree

12 files changed

+78
-54
lines changed

12 files changed

+78
-54
lines changed

doc/src/sgml/runtime.sgml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/runtime.sgml,v 1.67 2001/05/17 17:44:17 petere Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/runtime.sgml,v 1.68 2001/06/18 16:14:43 momjian Exp $
33
-->
44

55
<Chapter Id="runtime">
@@ -1201,6 +1201,17 @@ dynamic_library_path = '/usr/local/lib:/home/my_project/lib:$libdir:$libdir/cont
12011201
</listitem>
12021202
</varlistentry>
12031203

1204+
<term>AUSTRALIAN_TIMEZONES (<type>bool</type>)</term>
1205+
<listitem>
1206+
<para>
1207+
If set to true, <literal>CST</literal>, <literal>EST</literal>,
1208+
and <literal>SAT</literal> are interpreted as Australian
1209+
timezones rather than as North American Central/Eastern
1210+
Timezones and Saturday. The default is false.
1211+
</para>
1212+
</listitem>
1213+
</varlistentry>
1214+
12041215
<varlistentry>
12051216
<indexterm>
12061217
<primary>SSL</primary>

src/backend/utils/adt/datetime.c

Lines changed: 27 additions & 26 deletions
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.64 2001/05/03 22:53:07 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/datetime.c,v 1.65 2001/06/18 16:14:43 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -22,6 +22,7 @@
2222
#include <limits.h>
2323

2424
#include "miscadmin.h"
25+
#include "utils/guc.h"
2526
#include "utils/datetime.h"
2627

2728
static int DecodeNumber(int flen, char *field,
@@ -36,7 +37,6 @@ static int DecodeTimezone(char *str, int *tzp);
3637
static datetkn *datebsearch(char *key, datetkn *base, unsigned int nel);
3738
static int DecodeDate(char *str, int fmask, int *tmask, struct tm * tm);
3839

39-
#define USE_DATE_CACHE 1
4040
#define ROUND_ALL 0
4141

4242
static int DecodePosixTimezone(char *str, int *val);
@@ -117,11 +117,7 @@ static datetkn datetktbl[] = {
117117
{"cdt", DTZ, NEG(30)}, /* Central Daylight Time */
118118
{"cet", TZ, 6}, /* Central European Time */
119119
{"cetdst", DTZ, 12}, /* Central European Dayl.Time */
120-
#if USE_AUSTRALIAN_RULES
121-
{"cst", TZ, 63}, /* Australia Eastern Std Time */
122-
#else
123120
{"cst", TZ, NEG(36)}, /* Central Standard Time */
124-
#endif
125121
{DCURRENT, RESERV, DTK_CURRENT}, /* "current" is always now */
126122
{"dec", MONTH, 12},
127123
{"december", MONTH, 12},
@@ -134,11 +130,7 @@ static datetkn datetktbl[] = {
134130
{"eet", TZ, 12}, /* East. Europe, USSR Zone 1 */
135131
{"eetdst", DTZ, 18}, /* Eastern Europe */
136132
{EPOCH, RESERV, DTK_EPOCH}, /* "epoch" reserved for system epoch time */
137-
#if USE_AUSTRALIAN_RULES
138-
{"est", TZ, 60}, /* Australia Eastern Std Time */
139-
#else
140133
{"est", TZ, NEG(30)}, /* Eastern Standard Time */
141-
#endif
142134
{"feb", MONTH, 2},
143135
{"february", MONTH, 2},
144136
{"fri", DOW, 5},
@@ -199,11 +191,7 @@ static datetkn datetktbl[] = {
199191
{"pst", TZ, NEG(48)}, /* Pacific Standard Time */
200192
{"sadt", DTZ, 63}, /* S. Australian Dayl. Time */
201193
{"sast", TZ, 57}, /* South Australian Std Time */
202-
#if USE_AUSTRALIAN_RULES
203-
{"sat", TZ, 57},
204-
#else
205194
{"sat", DOW, 6},
206-
#endif
207195
{"saturday", DOW, 6},
208196
{"sep", MONTH, 9},
209197
{"sept", MONTH, 9},
@@ -247,6 +235,16 @@ static datetkn datetktbl[] = {
247235

248236
static unsigned int szdatetktbl = sizeof datetktbl / sizeof datetktbl[0];
249237

238+
/* Used for SET australian_timezones to override North American ones */
239+
static datetkn australian_datetktbl[] = {
240+
{"cst", TZ, 63}, /* Australia Eastern Std Time */
241+
{"est", TZ, 60}, /* Australia Eastern Std Time */
242+
{"sat", TZ, 57},
243+
};
244+
245+
static unsigned int australian_szdatetktbl = sizeof australian_datetktbl /
246+
sizeof australian_datetktbl[0];
247+
250248
static datetkn deltatktbl[] = {
251249
/* text token lexval */
252250
{"@", IGNORE, 0}, /* postgres relative time prefix */
@@ -327,13 +325,10 @@ static datetkn deltatktbl[] = {
327325

328326
static unsigned int szdeltatktbl = sizeof deltatktbl / sizeof deltatktbl[0];
329327

330-
#if USE_DATE_CACHE
331328
datetkn *datecache[MAXDATEFIELDS] = {NULL};
332329

333330
datetkn *deltacache[MAXDATEFIELDS] = {NULL};
334331

335-
#endif
336-
337332

338333
/*
339334
* Calendar time to Julian date conversions.
@@ -1618,18 +1613,19 @@ DecodeSpecial(int field, char *lowtoken, int *val)
16181613
int type;
16191614
datetkn *tp;
16201615

1621-
#if USE_DATE_CACHE
16221616
if ((datecache[field] != NULL)
16231617
&& (strncmp(lowtoken, datecache[field]->token, TOKMAXLEN) == 0))
16241618
tp = datecache[field];
16251619
else
16261620
{
1627-
#endif
1628-
tp = datebsearch(lowtoken, datetktbl, szdatetktbl);
1629-
#if USE_DATE_CACHE
1621+
tp = NULL;
1622+
if (Australian_timezones)
1623+
tp = datebsearch(lowtoken, australian_datetktbl,
1624+
australian_szdatetktbl);
1625+
if (!tp)
1626+
tp = datebsearch(lowtoken, datetktbl, szdatetktbl);
16301627
}
16311628
datecache[field] = tp;
1632-
#endif
16331629
if (tp == NULL)
16341630
{
16351631
type = IGNORE;
@@ -1937,18 +1933,14 @@ DecodeUnits(int field, char *lowtoken, int *val)
19371933
int type;
19381934
datetkn *tp;
19391935

1940-
#if USE_DATE_CACHE
19411936
if ((deltacache[field] != NULL)
19421937
&& (strncmp(lowtoken, deltacache[field]->token, TOKMAXLEN) == 0))
19431938
tp = deltacache[field];
19441939
else
19451940
{
1946-
#endif
19471941
tp = datebsearch(lowtoken, deltatktbl, szdeltatktbl);
1948-
#if USE_DATE_CACHE
19491942
}
19501943
deltacache[field] = tp;
1951-
#endif
19521944
if (tp == NULL)
19531945
{
19541946
type = IGNORE;
@@ -2455,3 +2447,12 @@ EncodeTimeSpan(struct tm * tm, double fsec, int style, char *str)
24552447

24562448
return 0;
24572449
} /* EncodeTimeSpan() */
2450+
2451+
2452+
void ClearDateCache(bool dummy)
2453+
{
2454+
int i;
2455+
2456+
for (i=0; i < MAXDATEFIELDS; i++)
2457+
datecache[i] = NULL;
2458+
}

src/backend/utils/misc/guc.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Support for grand unified configuration scheme, including SET
55
* command, configuration file, and command line options.
66
*
7-
* $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.38 2001/06/12 22:54:06 tgl Exp $
7+
* $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.39 2001/06/18 16:14:43 momjian Exp $
88
*
99
* Copyright 2000 by PostgreSQL Global Development Group
1010
* Written by Peter Eisentraut <peter_e@gmx.net>.
@@ -33,6 +33,7 @@
3333
#include "parser/parse_expr.h"
3434
#include "storage/proc.h"
3535
#include "tcop/tcopprot.h"
36+
#include "utils/datetime.h"
3637

3738

3839
/* XXX these should be in other modules' header files */
@@ -69,6 +70,8 @@ bool Show_btree_build_stats = false;
6970

7071
bool SQL_inheritance = true;
7172

73+
bool Australian_timezones = false;
74+
7275
#ifndef PG_KRB_SRVTAB
7376
#define PG_KRB_SRVTAB ""
7477
#endif
@@ -229,6 +232,9 @@ static struct config_bool
229232

230233
{"sql_inheritance", PGC_USERSET, &SQL_inheritance, true, NULL},
231234

235+
{"australian_timezones", PGC_USERSET, &Australian_timezones,
236+
false, ClearDateCache},
237+
232238
{"fixbtree", PGC_POSTMASTER, &FixBTree, true, NULL},
233239

234240
{NULL, 0, NULL, false, NULL}
@@ -327,8 +333,8 @@ static struct config_real
327333
DEFAULT_CPU_OPERATOR_COST, 0, DBL_MAX, NULL, NULL},
328334

329335
{"geqo_selection_bias", PGC_USERSET, &Geqo_selection_bias,
330-
DEFAULT_GEQO_SELECTION_BIAS, MIN_GEQO_SELECTION_BIAS,
331-
MAX_GEQO_SELECTION_BIAS, NULL, NULL},
336+
DEFAULT_GEQO_SELECTION_BIAS, MIN_GEQO_SELECTION_BIAS,
337+
MAX_GEQO_SELECTION_BIAS, NULL, NULL},
332338

333339
{NULL, 0, NULL, 0.0, 0.0, 0.0, NULL, NULL}
334340
};
@@ -360,8 +366,8 @@ static struct config_string
360366
"", NULL, NULL},
361367

362368
{"wal_sync_method", PGC_SIGHUP, &XLOG_sync_method,
363-
XLOG_sync_method_default,
364-
check_xlog_sync_method, assign_xlog_sync_method},
369+
XLOG_sync_method_default, check_xlog_sync_method,
370+
assign_xlog_sync_method},
365371

366372
{NULL, 0, NULL, NULL, NULL, NULL}
367373
};
@@ -956,6 +962,7 @@ _ShowOption(enum config_type opttype, struct config_generic *record)
956962
case PGC_BOOL:
957963
val = *((struct config_bool *) record)->variable ? "on" : "off";
958964
break;
965+
959966
case PGC_INT:
960967
snprintf(buffer, sizeof(buffer), "%d",
961968
*((struct config_int *) record)->variable);

src/backend/utils/misc/postgresql.conf.sample

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -84,24 +84,6 @@
8484
#geqo_random_seed = -1 # auto-compute seed
8585

8686

87-
#
88-
# Inheritance
89-
#
90-
#sql_inheritance = true
91-
92-
93-
#
94-
# Deadlock
95-
#
96-
#deadlock_timeout = 1000
97-
98-
99-
#
100-
# Expression Depth Limitation
101-
#
102-
#max_expr_depth = 10000 # min 10
103-
104-
10587
#
10688
# Write-ahead log (WAL)
10789
#
@@ -172,3 +154,13 @@
172154
#trace_lock_oidmin = 16384
173155
#trace_lock_table = 0
174156
#endif
157+
158+
159+
#
160+
# Misc
161+
#
162+
#sql_inheritance = true
163+
#australian_timezones = false
164+
#deadlock_timeout = 1000
165+
#max_expr_depth = 10000 # min 10
166+

src/include/utils/datetime.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
1010
* Portions Copyright (c) 1994, Regents of the University of California
1111
*
12-
* $Id: datetime.h,v 1.18 2001/05/03 22:53:07 tgl Exp $
12+
* $Id: datetime.h,v 1.19 2001/06/18 16:14:43 momjian Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -182,6 +182,7 @@ typedef struct
182182
char value; /* this may be unsigned, alas */
183183
} datetkn;
184184

185+
extern datetkn datetktbl[];
185186

186187
/* TMODULO()
187188
* Macro to replace modf(), which is broken on some platforms.
@@ -264,6 +265,7 @@ extern int EncodeTimeSpan(struct tm * tm, double fsec, int style, char *str);
264265

265266
extern int DecodeSpecial(int field, char *lowtoken, int *val);
266267
extern int DecodeUnits(int field, char *lowtoken, int *val);
268+
extern void ClearDateCache(bool);
267269

268270
extern int j2day(int jd);
269271

src/include/utils/guc.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* External declarations pertaining to backend/utils/misc/guc.c and
55
* backend/utils/misc/guc-file.l
66
*
7-
* $Id: guc.h,v 1.8 2001/06/12 22:54:06 tgl Exp $
7+
* $Id: guc.h,v 1.9 2001/06/18 16:14:43 momjian Exp $
88
*/
99
#ifndef GUC_H
1010
#define GUC_H
@@ -70,5 +70,6 @@ extern bool Show_query_stats;
7070
extern bool Show_btree_build_stats;
7171

7272
extern bool SQL_inheritance;
73+
extern bool Australian_timezones;
7374

7475
#endif /* GUC_H */

src/test/regress/expected/horology-no-DST-before-1970.out

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
--
55
-- date, time arithmetic
66
--
7+
-- needed so tests pass
8+
SET australian_timezones = 'off';
79
SELECT date '1981-02-03' + time '04:05:06' AS "Date + Time";
810
Date + Time
911
------------------------------

src/test/regress/expected/horology-solaris-1947.out

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
--
55
-- date, time arithmetic
66
--
7+
-- needed so tests pass
8+
SET australian_timezones = 'off';
79
SELECT date '1981-02-03' + time '04:05:06' AS "Date + Time";
810
Date + Time
911
------------------------------

src/test/regress/expected/horology.out

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
--
55
-- date, time arithmetic
66
--
7+
-- needed so tests pass
8+
SET australian_timezones = 'off';
79
SELECT date '1981-02-03' + time '04:05:06' AS "Date + Time";
810
Date + Time
911
------------------------------

src/test/regress/expected/timestamp.out

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
-- Shorthand values
55
-- Not directly usable for regression testing since these are not constants.
66
-- So, just try to test parser and hope for the best - thomas 97/04/26
7+
-- needed so tests pass
8+
SET australian_timezones = 'off';
79
SELECT (timestamp 'today' = (timestamp 'yesterday' + interval '1 day')) as "True";
810
True
911
------

src/test/regress/sql/horology.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
--
22
-- HOROLOGY
33
--
4-
54
--
65
-- date, time arithmetic
76
--
7+
-- needed so tests pass
8+
SET australian_timezones = 'off';
89

910
SELECT date '1981-02-03' + time '04:05:06' AS "Date + Time";
1011

src/test/regress/sql/timestamp.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
--
22
-- DATETIME
33
--
4-
54
-- Shorthand values
65
-- Not directly usable for regression testing since these are not constants.
76
-- So, just try to test parser and hope for the best - thomas 97/04/26
7+
-- needed so tests pass
8+
SET australian_timezones = 'off';
89

910
SELECT (timestamp 'today' = (timestamp 'yesterday' + interval '1 day')) as "True";
1011
SELECT (timestamp 'today' = (timestamp 'tomorrow' - interval '1 day')) as "True";

0 commit comments

Comments
 (0)