Skip to content

Commit 632c44d

Browse files
committed
Bring in a patch from Keith Parks to move the use of European dates
from a #define to a run-time option '-e' Man page was updated to reflect new option
1 parent ac3c926 commit 632c44d

File tree

9 files changed

+108
-46
lines changed

9 files changed

+108
-46
lines changed

src/backend/parser/sysfunc.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#include <time.h>
2020

2121
#include <config.h>
22+
#include <postgres.h>
23+
#include <miscadmin.h>
2224
#include <parser/sysfunc.h>
2325

2426
/*
@@ -33,13 +35,13 @@ static char *Sysfunc_system_date(void)
3335

3436
time(&cur_time_secs);
3537
cur_time_expanded = localtime(&cur_time_secs);
36-
#if defined(EUROPEAN_DATES)
37-
sprintf(buf, "%2.2d-%2.2d-%4.4d", cur_time_expanded->tm_mday,
38+
if (EuroDates == 1)
39+
sprintf(buf, "%2.2d-%2.2d-%4.4d", cur_time_expanded->tm_mday,
3840
cur_time_expanded->tm_mon+1, cur_time_expanded->tm_year+1900);
39-
#else
40-
sprintf(buf, "%2.2d-%2.2d-%4.4d", cur_time_expanded->tm_mon+1,
41+
else
42+
sprintf(buf, "%2.2d-%2.2d-%4.4d", cur_time_expanded->tm_mon+1,
4143
cur_time_expanded->tm_mday, cur_time_expanded->tm_year+1900);
42-
#endif
44+
4345
return &buf[0];
4446
}
4547

src/backend/postmaster/postmaster.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.34 1997/01/24 18:27:29 scrappy Exp $
13+
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.35 1997/01/26 15:30:23 scrappy Exp $
1414
*
1515
* NOTES
1616
*
@@ -251,7 +251,7 @@ PostmasterMain(int argc, char *argv[])
251251
DataDir = getenv("PGDATA"); /* default value */
252252

253253
opterr = 0;
254-
while ((opt = getopt(argc, argv, "a:B:b:D:dmM:no:p:Ss")) != EOF) {
254+
while ((opt = getopt(argc, argv, "a:B:b:D:demM:no:p:Ss")) != EOF) {
255255
switch (opt) {
256256
case 'a':
257257
/* Set the authentication system. */
@@ -294,13 +294,19 @@ PostmasterMain(int argc, char *argv[])
294294
else
295295
DebugLvl = 1;
296296
break;
297-
case 'm':
297+
case 'e':
298+
/*
299+
* Use european date formats.
300+
*/
301+
EuroDates = 1;
302+
break;
303+
case 'm':
298304
MultiplexedBackends = 1;
299305
MultiplexedBackendPort = atoi(optarg);
300306
break;
301307
case 'M':
302308
/* ignore this flag. This may be passed in because the
303-
program was run as 'postgres -M' instead of 'postmaster' */
309+
program was run as 'postgres -M' instead of 'postmaster' */
304310
break;
305311
case 'n':
306312
/* Don't reinit shared mem after abnormal exit */
@@ -1128,6 +1134,10 @@ DoExec(StartupInfo *packet, int portFd)
11281134
#endif /* WIN32 */
11291135

11301136
}
1137+
1138+
/* tell the backend we're using European dates */
1139+
if (EuroDates == 1)
1140+
av[ac++] = "-e";
11311141

11321142
/* tell the multiplexed backend to start on a certain port */
11331143
if (MultiplexedBackends) {

src/backend/tcop/postgres.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.25 1997/01/14 08:05:26 bryanh Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.26 1997/01/26 15:30:48 scrappy Exp $
1111
*
1212
* NOTES
1313
* this is the "main" module of the postgres backend and
@@ -784,6 +784,7 @@ PostgresMain(int argc, char *argv[])
784784
int flagQ;
785785
int flagS;
786786
int flagE;
787+
int flagEu;
787788
int flag;
788789

789790
char *DBName = NULL;
@@ -842,7 +843,7 @@ PostgresMain(int argc, char *argv[])
842843
* parse command line arguments
843844
* ----------------
844845
*/
845-
flagC = flagQ = flagS = flagE = ShowStats = 0;
846+
flagC = flagQ = flagS = flagE = flagEu = ShowStats = 0;
846847
ShowParserStats = ShowPlannerStats = ShowExecutorStats = 0;
847848

848849
/* get hostname is either the environment variable PGHOST
@@ -856,7 +857,7 @@ PostgresMain(int argc, char *argv[])
856857
DataDir = getenv("PGDATA"); /* default */
857858
multiplexedBackend = false; /* default */
858859

859-
while ((flag = getopt(argc, argv, "B:bCD:d:Ef:iLm:MNo:P:pQSst:x:F"))
860+
while ((flag = getopt(argc, argv, "B:bCD:d:Eef:iLm:MNo:P:pQSst:x:F"))
860861
!= EOF)
861862
switch (flag) {
862863

@@ -907,6 +908,14 @@ PostgresMain(int argc, char *argv[])
907908
flagE = 1;
908909
break;
909910

911+
case 'e':
912+
/* --------------------------
913+
* Use european date formats.
914+
* --------------------------
915+
*/
916+
flagEu = 1;
917+
break;
918+
910919
case 'F':
911920
/* --------------------
912921
* turn off fsync
@@ -1135,6 +1144,7 @@ PostgresMain(int argc, char *argv[])
11351144
Noversion = flagC;
11361145
Quiet = flagQ;
11371146
EchoQuery = flagE;
1147+
EuroDates = flagEu;
11381148

11391149
/* ----------------
11401150
* print flags
@@ -1146,6 +1156,7 @@ PostgresMain(int argc, char *argv[])
11461156
printf("\tNoversion = %c\n", Noversion ? 't' : 'f');
11471157
printf("\tstable = %c\n", flagS ? 't' : 'f');
11481158
printf("\ttimings = %c\n", ShowStats ? 't' : 'f');
1159+
printf("\tdates = %s\n", EuroDates ? "European" : "Normal");
11491160
printf("\tbufsize = %d\n", NBuffers);
11501161

11511162
printf("\tquery echo = %c\n", EchoQuery ? 't' : 'f');
@@ -1271,7 +1282,7 @@ PostgresMain(int argc, char *argv[])
12711282
*/
12721283
if (IsUnderPostmaster == false) {
12731284
puts("\nPOSTGRES backend interactive interface");
1274-
puts("$Revision: 1.25 $ $Date: 1997/01/14 08:05:26 $");
1285+
puts("$Revision: 1.26 $ $Date: 1997/01/26 15:30:48 $");
12751286
}
12761287

12771288
/* ----------------

src/backend/utils/adt/datetimes.c

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/datetimes.c,v 1.7 1996/11/14 21:38:58 scrappy Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/datetimes.c,v 1.8 1997/01/26 15:31:12 scrappy Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
1414
#include <stdio.h> /* for sprintf() */
1515
#include <string.h>
1616

1717
#include <postgres.h>
18+
#include <miscadmin.h>
1819
#include <utils/builtins.h>
1920
#include <utils/datetime.h>
2021

@@ -50,19 +51,19 @@ date_in(char *datestr)
5051
# define CHECK_DATE_LEN(datestr) 1
5152
#endif
5253

53-
#ifndef EUROPEAN_DATES
54-
if (!CHECK_DATE_LEN(datestr) ||
55-
sscanf(datestr, "%d%*c%d%*c%d", &m, &d, &y) != 3) {
56-
elog(WARN, "date_in: date \"%s\" not of the form mm-dd-yyyy",
57-
datestr);
58-
}
59-
#else
60-
if (!CHECK_DATE_LEN(datestr) ||
61-
sscanf(datestr, "%d%*c%d%*c%d", &d, &m, &y) != 3) {
62-
elog(WARN, "date_in: date \"%s\" not of the form dd-mm-yyyy",
63-
datestr);
54+
if (EuroDates == 1) { /* Expect european format dates */
55+
if (!CHECK_DATE_LEN(datestr) ||
56+
sscanf(datestr, "%d%*c%d%*c%d", &d, &m, &y) != 3) {
57+
elog(WARN, "date_in: date \"%s\" not of the form dd-mm-yyyy",
58+
datestr);
59+
}
60+
} else {
61+
if (!CHECK_DATE_LEN(datestr) ||
62+
sscanf(datestr, "%d%*c%d%*c%d", &m, &d, &y) != 3) {
63+
elog(WARN, "date_in: date \"%s\" not of the form mm-dd-yyyy",
64+
datestr);
65+
}
6466
}
65-
#endif
6667
if (y < 0 || y > 32767)
6768
elog(WARN, "date_in: year must be limited to values 0 through 32767 in \"%s\"", datestr);
6869
if (m < 1 || m > 12)
@@ -94,13 +95,12 @@ date_out(int4 dateVal)
9495
date = (DateADT*)&dateStore;
9596
dateStore = dateVal;
9697

97-
#ifndef EUROPEAN_DATES
98-
sprintf(datestr, "%02d-%02d-%04d",
99-
(int)date->month, (int)date->day, (int)date->year);
100-
#else
101-
sprintf(datestr, "%02d-%02d-%04d",
102-
(int)date->day, (int)date->month, (int)date->year);
103-
#endif
98+
if (EuroDates == 1) /* Output european format dates */
99+
sprintf(datestr, "%02d-%02d-%04d",
100+
(int)date->day, (int)date->month, (int)date->year);
101+
else
102+
sprintf(datestr, "%02d-%02d-%04d",
103+
(int)date->month, (int)date->day, (int)date->year);
104104

105105
return datestr;
106106
}

src/backend/utils/init/globals.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/init/globals.c,v 1.4 1997/01/14 08:05:36 bryanh Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/init/globals.c,v 1.5 1997/01/26 15:31:29 scrappy Exp $
1111
*
1212
* NOTES
1313
* Globals used all over the place should be declared here and not
@@ -65,6 +65,8 @@ bool IsPostmaster = false;
6565

6666
short DebugLvl = 0;
6767

68+
int EuroDates = 0;
69+
6870
char *IndexedCatalogNames[] = {
6971
AttributeRelationName,
7072
ProcedureRelationName,

src/include/config.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
/* Define one for either <history.h> or <readline/history.h>
2323
*/
24-
/* #undef HAVE_HISTORY */
24+
/* #undef HAVE_HISTORY */
2525

2626

2727
#define HAVE_SYS_SELECT_H
@@ -265,11 +265,6 @@ typedef unsigned char slock_t;
265265

266266
#define DEF_PGPORT "5432"
267267

268-
/* turn this on if you prefer European style dates instead of American
269-
* style dates
270-
*/
271-
/* #define EUROPEAN_DATES */
272-
273268
/*
274269
* If you do not plan to use Host based authentication,
275270
* comment out the following line

src/include/miscadmin.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
* Copyright (c) 1994, Regents of the University of California
1313
*
14-
* $Id: miscadmin.h,v 1.4 1996/11/14 10:25:42 bryanh Exp $
14+
* $Id: miscadmin.h,v 1.5 1997/01/26 15:32:06 scrappy Exp $
1515
*
1616
* NOTES
1717
* some of the information in this file will be moved to
@@ -57,6 +57,8 @@ extern bool IsPostmaster;
5757

5858
extern short DebugLvl;
5959

60+
extern int EuroDates;
61+
6062
extern Oid LastOidProcessed; /* for query rewrite */
6163

6264
#define MAX_PARSE_BUFFER 8192

src/man/postgres.1

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.\" This is -*-nroff-*-
22
.\" XXX standard disclaimer belongs here....
3-
.\" $Header: /cvsroot/pgsql/src/man/Attic/postgres.1,v 1.4 1996/12/11 22:58:14 momjian Exp $
3+
.\" $Header: /cvsroot/pgsql/src/man/Attic/postgres.1,v 1.5 1997/01/26 15:32:20 scrappy Exp $
44
.TH POSTGRES95 UNIX 12/08/96 Postgres95 Postgres95
55
.SH NAME
66
postgres \(em the Postgres backend server
@@ -25,6 +25,9 @@ filedes]
2525
[\c
2626
.BR "-Q"
2727
]
28+
[\c
29+
.BR "-e"
30+
]
2831
.br
2932
[\c
3033
.BR "-d"
@@ -78,9 +81,6 @@ has allocated for the backend server processes that it starts. If the
7881
backend is running standalone, this specifies the number of buffers to
7982
allocate. This value defaults to 64.
8083
.TP
81-
.BR "-E"
82-
Echo all queries.
83-
.TP
8484
.BR "-F"
8585
Disable automatic fsync() call after each transaction.
8686
This option improves performance, but an operating system crash
@@ -96,6 +96,26 @@ useful for interactive use.
9696
.BR "-Q"
9797
Specifies \*(lqquiet\*(rq mode.
9898
.TP
99+
.BR "-E"
100+
Echo all queries.
101+
.TP
102+
.BR "-e"
103+
The
104+
.IR "-e"
105+
option controls how dates are input to and output from the database.
106+
.IP
107+
If the
108+
.IR "-e"
109+
option is supplied, then all dates passed to and from the frontend
110+
processes will be assumed to be in
111+
.IR "European"
112+
format ie.
113+
.IR "DD-MM-YYYY"
114+
otherwise dates are input and output in
115+
.IR "American"
116+
format ie.
117+
.IR "MM-DD-YYYY"
118+
.TP
99119
.BR "-d" " debug_level"
100120
Turns on debugging at the numeric level
101121
.IR "debug_level" .

src/man/postmaster.1

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.\" This is -*-nroff-*-
22
.\" XXX standard disclaimer belongs here....
3-
.\" $Header: /cvsroot/pgsql/src/man/Attic/postmaster.1,v 1.2 1996/12/11 00:28:02 momjian Exp $
3+
.\" $Header: /cvsroot/pgsql/src/man/Attic/postmaster.1,v 1.3 1997/01/26 15:32:28 scrappy Exp $
44
.TH POSTMASTER UNIX 11/05/95 PostgreSQL PostgreSQL
55
.SH "NAME"
66
postmaster \(em run the Postgres postmaster
@@ -29,6 +29,9 @@ backend_pathname]
2929
[\c
3030
.BR "-n" \c
3131
]
32+
[\c
33+
.BR "-e" \c
34+
]
3235
.br
3336
[\c
3437
.BR "-o"
@@ -170,6 +173,23 @@ programmer can then use the
170173
.IR shmemdoc
171174
program to examine shared memory and semaphore state.
172175
.TP
176+
.BR "-e"
177+
The
178+
.IR "-e"
179+
option controls how dates are input to and output from the database.
180+
.IP
181+
If the
182+
.IR "-e"
183+
option is supplied, then all dates passed to and from the frontend
184+
processes will be assumed to be in
185+
.IR "European"
186+
format ie.
187+
.IR "DD-MM-YYYY"
188+
otherwise dates are input and output in
189+
.IR "American"
190+
format ie.
191+
.IR "MM-DD-YYYY"
192+
.TP
173193
.BR "-o" " backend_options"
174194
The
175195
.IR postgres (1)

0 commit comments

Comments
 (0)