From: Thomas Lockhart <Thomas.G.Lockhart@jpl.nasa.gov>

Subject: [HACKERS] More patches for date/time

I have accumulated several patches to add functionality to the datetime
and timespan data types as well as to fix reported porting bugs on non-BSD
machines. These patches are:

dt.c.patch              - add datetime_part(), fix bugs
dt.h.patch              - add quarter and timezone support, add prototypes
globals.c.patch         - add time and timezone variables
miscadmin.h.patch       - add time and timezone variables
nabstime.c.patch        - add datetime conversion routine
nabstime.h.patch        - add prototypes
pg_operator.h.patch     - add datetime operators, clean up formatting
pg_proc.h.patch         - add datetime functions, reassign conflicting date OIDs
pg_type.h.patch         - add datetime and timespan data types

The dt.c and pg_proc.h patches are fairly large; the latter mostly because I tried
to get some columns for existing entries to line up.
This commit is contained in:
Marc G. Fournier 1997-03-25 08:11:24 +00:00
parent d2a386d6e3
commit dfe0475362
9 changed files with 1443 additions and 692 deletions

File diff suppressed because it is too large Load Diff

View File

@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/nabstime.c,v 1.16 1997/03/21 18:53:28 scrappy Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/nabstime.c,v 1.17 1997/03/25 08:09:35 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
@ -62,13 +62,13 @@ GetCurrentAbsoluteTime(void)
CTimeZone = - tmnow->tm_gmtoff; /* tm_gmtoff is Sun/DEC-ism */
CDayLight = (tmnow->tm_isdst > 0);
/* XXX is there a better way to get local timezone string in V7? - tgl 97/03/18 */
strftime( CTZName, 8, "%Z", localtime(&now));
strftime( CTZName, MAXTZLEN, "%Z", localtime(&now));
#endif
#else /* ! USE_POSIX_TIME */
CTimeZone = tbnow.timezone * 60;
CDayLight = (tbnow.dstflag != 0);
/* XXX does this work to get the local timezone string in V7? - tgl 97/03/18 */
strftime( CTZName, 8, "%Z", localtime(&now));
strftime( CTZName, MAXTZLEN, "%Z", localtime(&now));
#endif
};
@ -102,41 +102,13 @@ GetCurrentTime(struct tm *tm)
} /* GetCurrentTime() */
/* nabstimein()
* Decode date/time string and return abstime.
*/
AbsoluteTime tm2abstime( struct tm *tm, int tz);
AbsoluteTime
nabstimein(char* str)
tm2abstime( struct tm *tm, int tz)
{
int sec;
double fsec;
int day, tz = 0;
struct tm date, *tm = &date;
int day, sec;
char *field[MAXDATEFIELDS];
char lowstr[MAXDATELEN+1];
int dtype;
int nf, ftype[MAXDATEFIELDS];
if (!PointerIsValid(str))
elog(WARN,"Bad (null) abstime external representation",NULL);
if (strlen(str) > MAXDATELEN)
elog( WARN, "Bad (length) abstime external representation '%s'",str);
if ((ParseDateTime( str, lowstr, field, ftype, MAXDATEFIELDS, &nf) != 0)
|| (DecodeDateTime( field, ftype, nf, &dtype, tm, &fsec, &tz) != 0))
elog( WARN, "Bad abstime external representation '%s'",str);
#ifdef DATEDEBUG
printf( "nabstimein- %d fields are type %d (DTK_DATE=%d)\n", nf, dtype, DTK_DATE);
#endif
switch (dtype) {
case DTK_DATE:
#if FALSE
return(dateconv( &date, tz));
#endif
/* validate, before going out of range on some members */
if (tm->tm_year < 1901 || tm->tm_year > 2038
|| tm->tm_mon < 1 || tm->tm_mon > 12
@ -172,27 +144,71 @@ printf( "nabstimein- %d fields are type %d (DTK_DATE=%d)\n", nf, dtype, DTK_DATE
return INVALID_ABSTIME;
return sec;
} /* tm2abstime() */
/* nabstimein()
* Decode date/time string and return abstime.
*/
AbsoluteTime
nabstimein(char* str)
{
AbsoluteTime result;
double fsec;
int tz = 0;
struct tm date, *tm = &date;
char *field[MAXDATEFIELDS];
char lowstr[MAXDATELEN+1];
int dtype;
int nf, ftype[MAXDATEFIELDS];
if (!PointerIsValid(str))
elog(WARN,"Bad (null) abstime external representation",NULL);
if (strlen(str) > MAXDATELEN)
elog( WARN, "Bad (length) abstime external representation '%s'",str);
if ((ParseDateTime( str, lowstr, field, ftype, MAXDATEFIELDS, &nf) != 0)
|| (DecodeDateTime( field, ftype, nf, &dtype, tm, &fsec, &tz) != 0))
elog( WARN, "Bad abstime external representation '%s'",str);
#ifdef DATEDEBUG
printf( "nabstimein- %d fields are type %d (DTK_DATE=%d)\n", nf, dtype, DTK_DATE);
#endif
switch (dtype) {
case DTK_DATE:
result = tm2abstime(tm, tz);
break;
case DTK_EPOCH:
return EPOCH_ABSTIME;
result = EPOCH_ABSTIME;
break;
case DTK_CURRENT:
return CURRENT_ABSTIME;
result = CURRENT_ABSTIME;
break;
case DTK_LATE:
return NOEND_ABSTIME;
result = NOEND_ABSTIME;
break;
case DTK_EARLY:
return NOSTART_ABSTIME;
result = NOSTART_ABSTIME;
break;
case DTK_INVALID:
return INVALID_ABSTIME;
result = INVALID_ABSTIME;
break;
default:
elog(WARN,"Bad abstime (internal coding error) '%s'",str);
result = INVALID_ABSTIME;
};
elog(WARN,"Bad abstime (internal coding error) '%s'",str);
return INVALID_ABSTIME;
return result;
} /* nabstimein() */
@ -432,3 +448,42 @@ abstimege(AbsoluteTime t1, AbsoluteTime t2)
return(t1 >= t2);
}
/* datetime_abstime()
* Convert datetime to abstime.
*/
AbsoluteTime
datetime_abstime(DateTime *datetime)
{
AbsoluteTime result;
double fsec;
struct tm tt, *tm = &tt;
if (!PointerIsValid(datetime)) {
result = INVALID_ABSTIME;
} else if (DATETIME_IS_INVALID(*datetime)) {
result = INVALID_ABSTIME;
} else if (DATETIME_IS_NOBEGIN(*datetime)) {
result = NOSTART_ABSTIME;
} else if (DATETIME_IS_NOEND(*datetime)) {
result = NOEND_ABSTIME;
} else {
if (DATETIME_IS_RELATIVE(*datetime)) {
datetime2tm( SetDateTime(*datetime), tm, &fsec);
result = tm2abstime( tm, 0);
} else if (datetime2tm( *datetime, tm, &fsec) == 0) {
result = tm2abstime( tm, 0);
} else {
result = INVALID_ABSTIME;
};
};
return(result);
} /* datetime_abstime() */

View File

@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/init/globals.c,v 1.7 1997/03/18 20:14:46 scrappy Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/init/globals.c,v 1.8 1997/03/25 08:09:43 scrappy Exp $
*
* NOTES
* Globals used all over the place should be declared here and not
@ -65,11 +65,12 @@ bool IsPostmaster = false;
short DebugLvl = 0;
int DateStyle = USE_ISO_DATES;
bool EuroDates = false;
bool HasCTZSet = false;
bool CDayLight = false;
int CTimeZone = 0;
char CTZName[8] = "";
char CTZName[MAXTZLEN+1] = "";
char DateFormat[20] = "%d-%m-%Y"; /* mjl: sizes! or better malloc? XXX */
char FloatFormat[20] = "%f";

View File

@ -7,7 +7,7 @@
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: pg_operator.h,v 1.5 1997/03/12 21:27:18 scrappy Exp $
* $Id: pg_operator.h,v 1.6 1997/03/25 08:10:37 scrappy Exp $
*
* NOTES
* the genbki.sh script reads this file and generates .bki
@ -185,7 +185,7 @@ DATA(insert OID = 513 ( "@@" PGUID 0 l t f 0 603 600 0 0 0 0 box
DATA(insert OID = 514 ( "*" PGUID 0 b t f 23 23 23 514 0 0 0 int4mul intltsel intltjoinsel ));
DATA(insert OID = 515 ( "!" PGUID 0 r t f 23 0 23 0 0 0 0 int4fac intltsel intltjoinsel ));
DATA(insert OID = 516 ( "!!" PGUID 0 l t f 0 23 23 0 0 0 0 int4fac intltsel intltjoinsel ));
DATA(insert OID = 517 ( "<===>" PGUID 0 b t f 600 600 23 0 0 0 0 pointdist intltsel intltjoinsel ));
DATA(insert OID = 517 ( "<===>" PGUID 0 b t f 600 600 701 0 0 0 0 point_distance intltsel intltjoinsel ));
DATA(insert OID = 518 ( "<>" PGUID 0 b t f 23 23 16 518 96 0 0 int4ne neqsel neqjoinsel ));
DATA(insert OID = 519 ( "<>" PGUID 0 b t f 21 21 16 519 94 0 0 int2ne neqsel neqjoinsel ));
DATA(insert OID = 520 ( ">" PGUID 0 b t f 21 21 16 95 0 0 0 int2gt intgtsel intgtjoinsel ));
@ -383,6 +383,7 @@ DATA(insert OID = 1067 ( "<=" PGUID 0 b t f 1043 1043 16 1069 1068 0 0
DATA(insert OID = 1068 ( ">" PGUID 0 b t f 1043 1043 16 1066 1067 0 0 varchargt intltsel intltjoinsel ));
DATA(insert OID = 1069 ( ">=" PGUID 0 b t f 1043 1043 16 1067 1066 0 0 varcharge intltsel intltjoinsel ));
/* date operators */
DATA(insert OID = 1093 ( "=" PGUID 0 b t t 1082 1082 16 1093 1094 1095 1095 date_eq eqsel eqjoinsel ));
DATA(insert OID = 1094 ( "<>" PGUID 0 b t f 1082 1082 16 1094 1093 0 0 date_ne neqsel neqjoinsel ));
DATA(insert OID = 1095 ( "<" PGUID 0 b t f 1082 1082 16 1097 1098 0 0 date_lt intltsel intltjoinsel ));
@ -393,6 +394,7 @@ DATA(insert OID = 1099 ( "-" PGUID 0 b t f 1082 1082 23 0 0 0 0 date_mi
DATA(insert OID = 1100 ( "+" PGUID 0 b t f 1082 23 1082 0 0 0 0 date_pli - - ));
DATA(insert OID = 1101 ( "-" PGUID 0 b t f 1082 23 1082 0 0 0 0 date_mii - - ));
/* time operators */
DATA(insert OID = 1108 ( "=" PGUID 0 b t t 1083 1083 16 1108 1109 1110 1110 time_eq eqsel eqjoinsel ));
DATA(insert OID = 1109 ( "<>" PGUID 0 b t f 1083 1083 16 1109 1108 0 0 time_ne neqsel neqjoinsel ));
DATA(insert OID = 1110 ( "<" PGUID 0 b t f 1083 1083 16 1112 1113 0 0 time_lt intltsel intltjoinsel ));
@ -400,6 +402,30 @@ DATA(insert OID = 1111 ( "<=" PGUID 0 b t f 1083 1083 16 1113 1112 0 0
DATA(insert OID = 1112 ( ">" PGUID 0 b t f 1083 1083 16 1110 1111 0 0 time_gt intltsel intltjoinsel ));
DATA(insert OID = 1113 ( ">=" PGUID 0 b t f 1083 1083 16 1111 1065 0 0 time_ge intltsel intltjoinsel ));
/* datetime operators */
/* name, owner, prec, kind, isleft, canhash, left, right, result, com, negate, lsortop, rsortop, oprcode, operrest, oprjoin */
DATA(insert OID = 1320 ( "=" PGUID 0 b t f 1184 1184 16 1320 1321 1322 1322 datetime_eq eqsel eqjoinsel ));
DATA(insert OID = 1321 ( "<>" PGUID 0 b t f 1184 1184 16 1321 1320 0 0 datetime_ne neqsel neqjoinsel ));
DATA(insert OID = 1322 ( "<" PGUID 0 b t f 1184 1184 16 1325 1325 0 0 datetime_lt intltsel intltjoinsel ));
DATA(insert OID = 1323 ( "<=" PGUID 0 b t f 1184 1184 16 1324 1324 0 0 datetime_le intltsel intltjoinsel ));
DATA(insert OID = 1324 ( ">" PGUID 0 b t f 1184 1184 16 1323 1323 0 0 datetime_gt intltsel intltjoinsel ));
DATA(insert OID = 1325 ( ">=" PGUID 0 b t f 1184 1184 16 1322 1322 0 0 datetime_ge intltsel intltjoinsel ));
DATA(insert OID = 1327 ( "+" PGUID 0 b t f 1184 1186 1184 1327 0 0 0 datetime_add_span - - ));
DATA(insert OID = 1328 ( "-" PGUID 0 b t f 1184 1184 1186 0 0 0 0 datetime_sub - - ));
/* timespan operators */
DATA(insert OID = 1330 ( "=" PGUID 0 b t f 1186 1186 16 1330 1331 1332 1332 timespan_eq eqsel eqjoinsel ));
DATA(insert OID = 1331 ( "<>" PGUID 0 b t f 1186 1186 16 1331 1330 0 0 timespan_ne neqsel neqjoinsel ));
DATA(insert OID = 1332 ( "<" PGUID 0 b t f 1186 1186 16 1335 1335 0 0 timespan_lt intltsel intltjoinsel ));
DATA(insert OID = 1333 ( "<=" PGUID 0 b t f 1186 1186 16 1334 1334 0 0 timespan_le intltsel intltjoinsel ));
DATA(insert OID = 1334 ( ">" PGUID 0 b t f 1186 1186 16 1333 1333 0 0 timespan_gt intltsel intltjoinsel ));
DATA(insert OID = 1335 ( ">=" PGUID 0 b t f 1186 1186 16 1332 1332 0 0 timespan_ge intltsel intltjoinsel ));
DATA(insert OID = 1336 ( "-" PGUID 0 b t f 0 1186 1186 0 0 0 0 timespan_um 0 0 ));
DATA(insert OID = 1337 ( "+" PGUID 0 b t f 1186 1186 1186 1337 0 0 0 timespan_add - - ));
DATA(insert OID = 1338 ( "-" PGUID 0 b t f 1186 1186 1186 0 0 0 0 timespan_sub - - ));
/* float48 operators */
DATA(insert OID = 1116 ( "+" PGUID 0 b t f 700 701 701 1116 0 0 0 float48pl - - ));
DATA(insert OID = 1117 ( "-" PGUID 0 b t f 700 701 701 0 0 0 0 float48mi - - ));
@ -463,6 +489,7 @@ DATA(insert OID = 1232 ( "~*" PGUID 0 b t f 1043 25 16 0 1233 0 0 text
DATA(insert OID = 1233 ( "!~*" PGUID 0 b t f 1043 25 16 0 1232 0 0 texticregexne neqsel neqjoinsel ));
DATA(insert OID = 1234 ( "~*" PGUID 0 b t f 1042 25 16 0 1235 0 0 texticregexeq eqsel eqjoinsel ));
DATA(insert OID = 1235 ( "!~*" PGUID 0 b t f 1042 25 16 0 1234 0 0 texticregexne neqsel neqjoinsel ));
DATA(insert OID = 1300 ( "=" PGUID 0 b t t 1296 1296 16 1300 1301 1302 1302 timestampeq eqsel eqjoinsel ));
DATA(insert OID = 1301 ( "<>" PGUID 0 b t f 1296 1296 16 1301 1300 0 0 timestampne neqsel neqjoinsel ));
DATA(insert OID = 1302 ( "<" PGUID 0 b t f 1296 1296 16 1303 1305 0 0 timestamplt intltsel intltjoinsel ));

View File

@ -6,7 +6,7 @@
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: pg_proc.h,v 1.13 1997/03/24 07:32:38 vadim Exp $
* $Id: pg_proc.h,v 1.14 1997/03/25 08:10:50 scrappy Exp $
*
* NOTES
* The script catalog/genbki.sh reads this file and generates .bki
@ -729,22 +729,51 @@ DATA(insert OID = 1089 ( date_gt PGUID 11 f t f 2 f 16 "1082 1082" 100
DATA(insert OID = 1090 ( date_ge PGUID 11 f t f 2 f 16 "1082 1082" 100 0 0 100 foo bar ));
DATA(insert OID = 1091 ( date_ne PGUID 11 f t f 2 f 16 "1082 1082" 100 0 0 100 foo bar ));
DATA(insert OID = 1092 ( date_cmp PGUID 11 f t f 2 f 23 "1082 1082" 100 0 0 100 foo bar ));
DATA(insert OID = 1093 ( date_larger PGUID 11 f t f 2 f 1082 "1082 1082" 100 0 0 100 foo bar ));
DATA(insert OID = 1094 ( date_smaller PGUID 11 f t f 2 f 1082 "1082 1082" 100 0 0 100 foo bar ));
DATA(insert OID = 1095 ( date_mi PGUID 11 f t f 2 f 23 "1082 1082" 100 0 0 100 foo bar ));
DATA(insert OID = 1096 ( date_pli PGUID 11 f t f 2 f 1082 "1082 23" 100 0 0 100 foo bar ));
DATA(insert OID = 1097 ( date_mii PGUID 11 f t f 2 f 1082 "1082 23" 100 0 0 100 foo bar ));
DATA(insert OID = 1099 ( time_in PGUID 11 f t f 1 f 1083 "0" 100 0 0 100 foo bar ));
/* OIDS 1100 - 1199 */
DATA(insert OID = 1100 ( time_out PGUID 11 f t f 1 f 23 "0" 100 0 0 100 foo bar ));
DATA(insert OID = 1101 ( time_eq PGUID 11 f t f 2 f 16 "1083 1083" 100 0 0 100 foo bar ));
DATA(insert OID = 1102 ( time_lt PGUID 11 f t f 2 f 16 "1083 1083" 100 0 0 100 foo bar ));
DATA(insert OID = 1103 ( time_le PGUID 11 f t f 2 f 16 "1083 1083" 100 0 0 100 foo bar ));
DATA(insert OID = 1104 ( time_gt PGUID 11 f t f 2 f 16 "1083 1083" 100 0 0 100 foo bar ));
DATA(insert OID = 1105 ( time_ge PGUID 11 f t f 2 f 16 "1083 1083" 100 0 0 100 foo bar ));
DATA(insert OID = 1106 ( time_ne PGUID 11 f t f 2 f 16 "1083 1083" 100 0 0 100 foo bar ));
DATA(insert OID = 1107 ( time_cmp PGUID 11 f t f 2 f 23 "1083 1083" 100 0 0 100 foo bar ));
DATA(insert OID = 1138 ( date_larger PGUID 11 f t f 2 f 1082 "1082 1082" 100 0 0 100 foo bar ));
DATA(insert OID = 1139 ( date_smaller PGUID 11 f t f 2 f 1082 "1082 1082" 100 0 0 100 foo bar ));
DATA(insert OID = 1140 ( date_mi PGUID 11 f t f 2 f 23 "1082 1082" 100 0 0 100 foo bar ));
DATA(insert OID = 1141 ( date_pli PGUID 11 f t f 2 f 1082 "1082 23" 100 0 0 100 foo bar ));
DATA(insert OID = 1142 ( date_mii PGUID 11 f t f 2 f 1082 "1082 23" 100 0 0 100 foo bar ));
DATA(insert OID = 1143 ( time_in PGUID 11 f t f 1 f 1083 "0" 100 0 0 100 foo bar ));
DATA(insert OID = 1144 ( time_out PGUID 11 f t f 1 f 23 "0" 100 0 0 100 foo bar ));
DATA(insert OID = 1145 ( time_eq PGUID 11 f t f 2 f 16 "1083 1083" 100 0 0 100 foo bar ));
DATA(insert OID = 1150 ( datetime_in PGUID 11 f t f 1 f 1184 "0" 100 0 0 100 foo bar ));
DATA(insert OID = 1151 ( datetime_out PGUID 11 f t f 1 f 23 "0" 100 0 0 100 foo bar ));
DATA(insert OID = 1152 ( datetime_eq PGUID 11 f t f 2 f 16 "1184 1184" 100 0 0 100 foo bar ));
DATA(insert OID = 1153 ( datetime_ne PGUID 11 f t f 2 f 16 "1184 1184" 100 0 0 100 foo bar ));
DATA(insert OID = 1154 ( datetime_lt PGUID 11 f t f 2 f 16 "1184 1184" 100 0 0 100 foo bar ));
DATA(insert OID = 1155 ( datetime_le PGUID 11 f t f 2 f 16 "1184 1184" 100 0 0 100 foo bar ));
DATA(insert OID = 1156 ( datetime_ge PGUID 11 f t f 2 f 16 "1184 1184" 100 0 0 100 foo bar ));
DATA(insert OID = 1157 ( datetime_gt PGUID 11 f t f 2 f 16 "1184 1184" 100 0 0 100 foo bar ));
/* reserve OIDs 1158-1159 for additional date/time conversion routines! tgl 97/03/19 */
DATA(insert OID = 1160 ( timespan_in PGUID 11 f t f 1 f 1186 "0" 100 0 0 100 foo bar ));
DATA(insert OID = 1161 ( timespan_out PGUID 11 f t f 1 f 23 "0" 100 0 0 100 foo bar ));
DATA(insert OID = 1162 ( timespan_eq PGUID 11 f t f 2 f 16 "1186 1186" 100 0 0 100 foo bar ));
DATA(insert OID = 1163 ( timespan_ne PGUID 11 f t f 2 f 16 "1186 1186" 100 0 0 100 foo bar ));
DATA(insert OID = 1164 ( timespan_lt PGUID 11 f t f 2 f 16 "1186 1186" 100 0 0 100 foo bar ));
DATA(insert OID = 1165 ( timespan_le PGUID 11 f t f 2 f 16 "1186 1186" 100 0 0 100 foo bar ));
DATA(insert OID = 1166 ( timespan_ge PGUID 11 f t f 2 f 16 "1186 1186" 100 0 0 100 foo bar ));
DATA(insert OID = 1167 ( timespan_gt PGUID 11 f t f 2 f 16 "1186 1186" 100 0 0 100 foo bar ));
DATA(insert OID = 1168 ( timespan_um PGUID 11 f t f 1 f 1186 "1186" 100 0 0 100 foo bar ));
DATA(insert OID = 1169 ( timespan_add PGUID 11 f t f 2 f 1186 "1186 1186" 100 0 0 100 foo bar ));
DATA(insert OID = 1170 ( timespan_sub PGUID 11 f t f 2 f 1186 "1186 1186" 100 0 0 100 foo bar ));
DATA(insert OID = 1171 ( datetime_part PGUID 11 f t f 2 f 701 "25 1184" 100 0 0 100 foo bar ));
DATA(insert OID = 1172 ( timespan_part PGUID 11 f t f 2 f 701 "25 1186" 100 0 0 100 foo bar ));
/* reserve OIDs 1173-1180 for additional date/time conversion routines! tgl 97/03/19 */
DATA(insert OID = 1188 ( datetime_sub PGUID 11 f t f 2 f 1186 "1184 1184" 100 0 0 100 foo bar ));
DATA(insert OID = 1189 ( datetime_add_span PGUID 11 f t f 2 f 1184 "1184 1186" 100 0 0 100 foo bar ));
DATA(insert OID = 1190 ( datetime_sub_span PGUID 11 f t f 2 f 1184 "1184 1186" 100 0 0 100 foo bar ));
/* reserve OIDs 1191-1199 for additional date/time conversion routines! tgl 97/03/19 */
DATA(insert OID = 1200 ( int42reltime PGUID 11 f t f 1 f 703 "21" 100 0 0 100 foo bar ));
DATA(insert OID = 1290 ( char2icregexeq PGUID 11 f t f 2 f 16 "409 25" 100 0 0 100 foo bar ));

View File

@ -7,7 +7,7 @@
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: pg_type.h,v 1.8 1997/03/12 21:27:41 scrappy Exp $
* $Id: pg_type.h,v 1.9 1997/03/25 08:11:01 scrappy Exp $
*
* NOTES
* the genbki.sh script reads this file and generates .bki
@ -32,7 +32,7 @@
* typedef struct FormData_pg_type
*
* Some of the values in a pg_type instance are copied into
* pg_attribute intances. Some parts of Postgres use the pg_type copy,
* pg_attribute instances. Some parts of Postgres use the pg_type copy,
* while others use the pg_attribute copy, so they must match.
* See struct FormData_pg_attribute for details.
* ----------------
@ -57,6 +57,12 @@ CATALOG(pg_type) BOOTSTRAP {
may be an oversimplification. Also, there appear to be bugs in which
Postgres doesn't ignore typbyval when it should, but I'm
afraid to change them until I see proof of damage. -BRYANH 96.08).
(Postgres crashes if typbyval is true, the declared length is 8,
and the I/O routines are written to expect pass by reference.
Note that float4 is written for pass by reference and has a declared length
of 4 bytes, so it looks like pass by reference must be consistant
with the declared length, and typbyval is used somewhere. - tgl 97/03/20)
*/
char typtype;
bool typisdefined;
@ -66,6 +72,9 @@ CATALOG(pg_type) BOOTSTRAP {
/* typelem is NULL if this is not an array type. If this is an array
type, typelem is the OID of the type of the elements of the array
(it identifies another row in Table pg_type).
(Note that zero ("0") rather than _null_ is used
in the declarations. - tgl 97/03/20)
*/
regproc typinput;
regproc typoutput;
@ -289,10 +298,23 @@ DATA(insert OID = 1042 ( bpchar PGUID -1 -1 f b t \054 0 18 bpcharin bpcharou
DATA(insert OID = 1043 ( varchar PGUID -1 -1 f b t \054 0 18 varcharin varcharout varcharin varcharout i _null_ ));
DATA(insert OID = 1082 ( date PGUID 4 10 t b t \054 0 0 date_in date_out date_in date_out i _null_ ));
#define DATEOID 1082
DATA(insert OID = 1083 ( time PGUID 8 16 f b t \054 0 0 time_in time_out time_in time_out i _null_ ));
#define TIMEOID 1083
/* OIDS 1100 - 1199 */
DATA(insert OID = 1182 ( _date PGUID -1 -1 f b t \054 0 1082 array_in array_out array_in array_out i _null_ ));
DATA(insert OID = 1183 ( _time PGUID -1 -1 f b t \054 0 1083 array_in array_out array_in array_out d _null_ ));
DATA(insert OID = 1184 ( datetime PGUID 8 47 f b t \054 0 0 datetime_in datetime_out datetime_in datetime_out d _null_ ));
#define DATETIMEOID 1184
DATA(insert OID = 1185 ( _datetime PGUID -1 -1 f b t \054 0 1184 array_in array_out array_in array_out d _null_ ));
DATA(insert OID = 1186 ( timespan PGUID 12 47 f b t \054 0 0 timespan_in timespan_out timespan_in timespan_out d _null_ ));
#define TIMESPANOID 1186
DATA(insert OID = 1187 ( _timespan PGUID -1 -1 f b t \054 0 1186 array_in array_out array_in array_out d _null_ ));
/* OIDS 1200 - 1299 */
DATA(insert OID = 1296 ( timestamp PGUID 4 19 t b t \054 0 0 timestamp_in timestamp_out timestamp_in timestamp_out i _null_ ));
#define TIMESTAMPOID 1296
/*
* prototypes for functions in pg_type.c

View File

@ -11,7 +11,7 @@
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: miscadmin.h,v 1.7 1997/03/18 20:15:19 scrappy Exp $
* $Id: miscadmin.h,v 1.8 1997/03/25 08:09:59 scrappy Exp $
*
* NOTES
* some of the information in this file will be moved to
@ -58,12 +58,28 @@ extern bool IsPostmaster;
extern short DebugLvl;
/* Date/Time Configuration
* HasCTZSet if client timezone is specified by client.
*
* Constants to pass info from runtime environment:
* USE_POSTGRES_DATES specifies traditional postgres format for output.
* USE_ISO_DATES specifies ISO-compliant format for output.
* USE_SQL_DATES specified Oracle/Ingres-compliant format for output.
*
* DateStyle specifies preference for date formatting for output.
* EuroDates if client prefers dates interpreted and written w/European conventions.
*
* HasCTZSet if client timezone is specified by client.
* CDayLight is the apparent daylight savings time status.
* CTimeZone is the timezone offset in seconds.
* CTZName is the timezone label.
*/
#define MAXTZLEN 7
#define USE_POSTGRES_DATES 0
#define USE_ISO_DATES 1
#define USE_SQL_DATES 2
extern int DateStyle;
extern bool EuroDates;
extern bool HasCTZSet;
extern bool CDayLight;

View File

@ -8,7 +8,7 @@
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: dt.h,v 1.2 1997/03/18 16:36:50 scrappy Exp $
* $Id: dt.h,v 1.3 1997/03/25 08:11:18 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
@ -16,19 +16,23 @@
#define DT_H
#include <time.h>
#include <math.h>
/*
* DateTime represents absolute time.
* TimeSpan represents delta time.
* TimeSpan represents delta time. Keep track of months (and years)
* separately since the elapsed time spanned is unknown until instantiated
* relative to an absolute time.
*
* Note that Postgres uses "time interval" to mean a bounded interval,
* consisting of a beginning and ending time, not a time span.
* consisting of a beginning and ending time, not a time span - tgl 97/03/20
*/
typedef double DateTime;
typedef struct {
double time; /* all time units other than months and years */
int4 month; /* months and years */
int4 month; /* months and years, after time for alignment */
} TimeSpan;
@ -45,6 +49,7 @@ typedef struct {
* Other alternate forms are hardcoded into token tables in dt.c.
* ----------------------------------------------------------------
*/
#define DAGO "ago"
#define DCURRENT "current"
#define EPOCH "epoch"
@ -65,12 +70,14 @@ typedef struct {
#define DDAY "day"
#define DWEEK "week"
#define DMONTH "month"
#define DQUARTER "quarter"
#define DYEAR "year"
#define DDECADE "decade"
#define DCENTURY "century"
#define DMILLENIUM "millenium"
#define DA_D "ad"
#define DB_C "bc"
#define DTIMEZONE "timezone"
/*
* Fundamental time field definitions for parsing.
@ -78,6 +85,7 @@ typedef struct {
* Meridian: am, pm, or 24-hour style.
* Millenium: ad, bc
*/
#define AM 0
#define PM 1
#define HR24 2
@ -90,6 +98,7 @@ typedef struct {
* Can't have more of these than there are bits in an unsigned int
* since these are turned into bit masks during parsing and decoding.
*/
#define RESERV 0
#define MONTH 1
#define YEAR 2
@ -116,6 +125,7 @@ typedef struct {
* These need to fit into the datetkn table type.
* At the moment, that means keep them within [-127,127].
*/
#define DTK_NUMBER 0
#define DTK_STRING 1
@ -143,17 +153,19 @@ typedef struct {
#define DTK_DAY 36
#define DTK_WEEK 37
#define DTK_MONTH 38
#define DTK_YEAR 39
#define DTK_DECADE 40
#define DTK_CENTURY 41
#define DTK_MILLENIUM 42
#define DTK_MILLISEC 43
#define DTK_MICROSEC 44
#define DTK_AGO 45
#define DTK_QUARTER 39
#define DTK_YEAR 40
#define DTK_DECADE 41
#define DTK_CENTURY 42
#define DTK_MILLENIUM 43
#define DTK_MILLISEC 44
#define DTK_MICROSEC 45
#define DTK_AGO 46
/*
* Bit mask definitions for time parsing.
*/
#define DTK_M(t) (0x01 << t)
#define DTK_DATE_M (DTK_M(YEAR) | DTK_M(MONTH) | DTK_M(DAY))
@ -174,21 +186,95 @@ typedef struct {
char value; /* this may be unsigned, alas */
} datetkn;
extern void GetCurrentTime(struct tm *tm);
#ifdef NAN
#define DT_INVALID (NAN)
#else
#define DT_INVALID (DBL_MIN+DBL_MIN)
#endif
#ifdef HUGE_VAL
#define DT_NOBEGIN (-HUGE_VAL)
#define DT_NOEND (HUGE_VAL)
#else
#define DT_NOBEGIN (-DBL_MAX)
#define DT_NOEND (DBL_MAX)
#endif
#define DT_CURRENT (DBL_MIN)
#define DT_EPOCH (-DBL_MIN)
#define DATETIME_INVALID(j) {j = DT_INVALID;}
#ifdef NAN
#define DATETIME_IS_INVALID(j) (isnan(j))
#else
#define DATETIME_IS_INVALID(j) (j == DT_INVALID)
#endif
#define DATETIME_NOBEGIN(j) {j = DT_NOBEGIN;}
#define DATETIME_IS_NOBEGIN(j) (j == DT_NOBEGIN)
#define DATETIME_NOEND(j) {j = DT_NOEND;}
#define DATETIME_IS_NOEND(j) (j == DT_NOEND)
#define DATETIME_CURRENT(j) {j = DT_CURRENT;}
#define DATETIME_IS_CURRENT(j) (j == DT_CURRENT)
#define DATETIME_EPOCH(j) {j = DT_EPOCH;}
#define DATETIME_IS_EPOCH(j) (j == DT_EPOCH)
#define DATETIME_IS_RELATIVE(j) (DATETIME_IS_CURRENT(j) || DATETIME_IS_EPOCH(j))
#define DATETIME_NOT_FINITE(j) (DATETIME_IS_INVALID(j) \
|| DATETIME_IS_NOBEGIN(j) || DATETIME_IS_NOEND(j))
#define DATETIME_IS_RESERVED(j) (DATETIME_IS_RELATIVE(j) || DATETIME_NOT_FINITE(j))
#define TIMESPAN_INVALID(j) {j->time = DT_INVALID;}
#ifdef NAN
#define TIMESPAN_IS_INVALID(j) (isnan((j).time))
#else
#define TIMESPAN_IS_INVALID(j) ((j).time == DT_INVALID)
#endif
#define TIME_PREC 1e-6
#define JROUND(j) (rint(((double) j)/TIME_PREC)*TIME_PREC)
/*
* dt.c prototypes
*/
extern DateTime *datetime_in( char *str);
extern char *datetime_out( DateTime *dt);
extern bool datetime_eq(DateTime *dt1, DateTime *dt2);
extern bool datetime_ne(DateTime *dt1, DateTime *dt2);
extern bool datetime_lt(DateTime *dt1, DateTime *dt2);
extern bool datetime_le(DateTime *dt1, DateTime *dt2);
extern bool datetime_ge(DateTime *dt1, DateTime *dt2);
extern bool datetime_gt(DateTime *dt1, DateTime *dt2);
extern TimeSpan *timespan_in(char *str);
extern char *timespan_out(TimeSpan *span);
extern bool timespan_eq(TimeSpan *span1, TimeSpan *span2);
extern bool timespan_ne(TimeSpan *span1, TimeSpan *span2);
extern bool timespan_lt(TimeSpan *span1, TimeSpan *span2);
extern bool timespan_le(TimeSpan *span1, TimeSpan *span2);
extern bool timespan_ge(TimeSpan *span1, TimeSpan *span2);
extern bool timespan_gt(TimeSpan *span1, TimeSpan *span2);
float64 datetime_part(text *units, DateTime *datetime);
float64 timespan_part(text *units, TimeSpan *timespan);
extern TimeSpan *timespan_um(TimeSpan *span);
extern TimeSpan *timespan_add(TimeSpan *span1, TimeSpan *span2);
extern TimeSpan *timespan_sub(TimeSpan *span1, TimeSpan *span2);
extern TimeSpan *datetime_sub(DateTime *dt1, DateTime *dt2);
extern DateTime *datetime_add_span(DateTime *dt, TimeSpan *span);
extern DateTime *datetime_sub_span(DateTime *dt, TimeSpan *span);
extern TimeSpan *timespan_add(TimeSpan *span1, TimeSpan *span2);
extern TimeSpan *timespan_sub(TimeSpan *span1, TimeSpan *span2);
extern void GetCurrentTime(struct tm *tm);
DateTime SetDateTime(DateTime datetime);
DateTime tm2datetime(struct tm *tm, double fsec, int tzp);
int datetime2tm( DateTime dt, struct tm *tm, double *fsec);
int timespan2tm(TimeSpan span, struct tm *tm, float8 *fsec);
int tm2timespan(struct tm *tm, double fsec, TimeSpan *span);
extern DateTime dt2local( DateTime dt, int timezone);
@ -199,12 +285,8 @@ extern int j2day( int jd);
extern double time2t(const int hour, const int min, const double sec);
extern void dt2time(DateTime dt, int *hour, int *min, double *sec);
/*
extern void GetCurrentTime(struct tm *tm);
*/
extern int ParseDateTime( char *timestr, char *lowstr,
char *field[], int ftype[], int maxfields, int *numfields);
extern int DecodeDateTime( char *field[], int ftype[],
int nf, int *dtype, struct tm *tm, double *fsec, int *tzp);
extern int DecodeDate(char *str, int fmask, int *tmask, struct tm *tm);
@ -223,11 +305,10 @@ extern int DecodeDateDelta( char *field[], int ftype[],
int nf, int *dtype, struct tm *tm, double *fsec);
extern int DecodeUnits(int field, char *lowtoken, int *val);
extern int EncodeSpecialDateTime(DateTime *dt, char *str);
extern int EncodeSpecialDateTime(DateTime dt, char *str);
extern int EncodePostgresDate(struct tm *tm, double fsec, char *str);
extern int EncodePostgresSpan(struct tm *tm, double fsec, char *str);
extern datetkn *datebsearch(char *key, datetkn *base, unsigned int nel);
#endif /* DT_H */

View File

@ -6,7 +6,7 @@
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: nabstime.h,v 1.5 1997/03/14 23:33:29 scrappy Exp $
* $Id: nabstime.h,v 1.6 1997/03/25 08:11:24 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
@ -115,8 +115,6 @@ extern AbsoluteTime GetCurrentAbsoluteTime(void);
extern AbsoluteTime nabstimein(char *timestr);
extern char *nabstimeout(AbsoluteTime time);
extern bool AbsoluteTimeIsBefore(AbsoluteTime time1, AbsoluteTime time2);
extern bool AbsoluteTimeIsAfter(AbsoluteTime time1, AbsoluteTime time2);
extern bool abstimeeq(AbsoluteTime t1, AbsoluteTime t2);
extern bool abstimene(AbsoluteTime t1, AbsoluteTime t2);
extern bool abstimelt(AbsoluteTime t1, AbsoluteTime t2);
@ -124,6 +122,10 @@ extern bool abstimegt(AbsoluteTime t1, AbsoluteTime t2);
extern bool abstimele(AbsoluteTime t1, AbsoluteTime t2);
extern bool abstimege(AbsoluteTime t1, AbsoluteTime t2);
extern AbsoluteTime datetime_abstime(DateTime *datetime);
extern bool AbsoluteTimeIsBefore(AbsoluteTime time1, AbsoluteTime time2);
extern bool AbsoluteTimeIsAfter(AbsoluteTime time1, AbsoluteTime time2);
extern AbsoluteTime dateconv(struct tm *tm, int zone);
extern time_t qmktime(struct tm *tp);