bring in Thomas's updates for the date/time code...
--- /dev/null
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "postgres.h"
+#include "libpq/pqcomm.h"
+
+/* --------------------------------------------------------------------- */
+/* Is the other way around than system ntoh/hton, so we roll our own
+ here */
+
+#if BYTE_ORDER == LITTLE_ENDIAN
+#define ntoh_s(n) n
+#define ntoh_l(n) n
+#define hton_s(n) n
+#define hton_l(n) n
+#endif
+#if BYTE_ORDER == BIG_ENDIAN
+#define ntoh_s(n) (u_short)(((u_char *) &n)[0] << 8 | ((u_char *) &n)[1]);
+#define ntoh_l(n) (u_long)(((u_char *)&n)[0] << 24 | ((u_char *)&n)[1] << 16 |\
+ ((u_char *)&n)[2] << 8 | ((u_char *)&n)[3]);
+#define hton_s(n) (ntoh_s(n))
+#define hton_l(n) (ntoh_l(n))
+#endif
+#if BYTE_ORDER == PDP_ENDIAN
+#endif
+#ifndef ntoh_s
+#error Please write byte order macros
+#endif
+
+/* --------------------------------------------------------------------- */
+int pqPutShort(const int integer, FILE *f)
+ {
+ int retval = 0;
+ u_short n;
+
+ n = hton_s(integer);
+ if(fwrite(&n, sizeof(u_short), 1, f) != 1)
+ retval = 1;
+
+ return retval;
+ }
+
+/* --------------------------------------------------------------------- */
+int pqPutLong(const int integer, FILE *f)
+ {
+ int retval = 0;
+ u_long n;
+
+ n = hton_l(integer);
+ if(fwrite(&n, sizeof(u_long), 1, f) != 1)
+ retval = 1;
+
+ return retval;
+ }
+
+/* --------------------------------------------------------------------- */
+int pqGetShort(int *result, FILE *f)
+ {
+ int retval = 0;
+ u_short n;
+
+ if(fread(&n, sizeof(u_short), 1, f) != 1)
+ retval = 1;
+
+ *result = ntoh_s(n);
+ return retval;
+ }
+
+/* --------------------------------------------------------------------- */
+int pqGetLong(int *result, FILE *f)
+ {
+ int retval = 0;
+ u_long n;
+
+ if(fread(&n, sizeof(u_long), 1, f) != 1)
+ retval = 1;
+
+ *result = ntoh_l(n);
+ return retval;
+ }
+
+/* --------------------------------------------------------------------- */
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/dt.c,v 1.6 1997/03/16 19:03:20 scrappy Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/dt.c,v 1.7 1997/03/18 16:35:17 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
#include <string.h>
#include <sys/types.h>
#include <errno.h>
-#ifdef HAVE_VALUES_H
-# include <values.h>
-#else
-# include <float.h>
-# ifndef MINDOUBLE
-# define MINDOUBLE DBL_MIN
-# endif
-#endif
#include "postgres.h"
+#include <miscadmin.h>
+#ifndef USE_POSIX_TIME
+#include <sys/timeb.h>
+#endif
#include "utils/builtins.h"
-extern int EuroDates;
-
-#define MAXDATEFIELDS 25
-
#define USE_DATE_CACHE 1
-extern char *tzname[2];
-extern long int timezone;
-extern int daylight;
-
#define JTIME_INVALID (NAN)
#define DATETIME_INVALID(j) {*j = JTIME_INVALID;}
#define DATETIME_IS_INVALID(j) (isnan(*j))
if (tzp != 0) {
*result = dt2local(*result, -tzp);
} else {
- *result = dt2local(*result, -timezone);
+ *result = dt2local(*result, -CTimeZone);
};
#ifdef DATEDEBUG
printf( "datetime_in- date is %f\n", *result);
} else {
- time = (modf( dt2local( *dt, timezone)/86400, &date)*86400);
+ time = (modf( dt2local( *dt, CTimeZone)/86400, &date)*86400);
date += date2j(2000,1,1);
if (time < 0) {
time += 86400;
tm->tm_isdst = -1;
#ifdef DATEDEBUG
-printf( "datetime_out- timezone is %s/%s; offset is %ld; daylight is %d\n",
- tzname[0], tzname[1], timezone, daylight);
+printf( "datetime_out- timezone is %s; offset is %ld; daylight is %d\n",
+ CTZName, CTimeZone, CDayLight);
#endif
EncodePostgresDate(tm, fsec, buf);
* Returns the number of seconds since epoch (J2000)
*/
-#ifndef USE_POSIX_TIME
-long int timezone;
-long int daylight;
-#endif
-
-
/* ParseDateTime()
* Break string into tokens based on a date/time context.
*/
tm->tm_min = 0;
tm->tm_sec = 0;
tm->tm_isdst = -1; /* don't know daylight savings time status apriori */
- if (tzp != NULL) *tzp = timezone;
+ if (tzp != NULL) *tzp = CTimeZone;
for (i = 0; i < nf; i++) {
#ifdef DATEDEBUG
tm->tm_isdst = -1;
#ifdef DATEDEBUG
-printf( "EncodePostgresDate- timezone is %s/%s; offset is %ld; daylight is %d\n",
- tzname[0], tzname[1], timezone, daylight);
+printf( "EncodePostgresDate- timezone is %s; offset is %ld; daylight is %d\n",
+ CTZName, CTimeZone, CDayLight);
#endif
day = date2j( tm->tm_year, tm->tm_mon, tm->tm_mday);
if (EuroDates) {
sprintf( str, "%3s %02d/%02d/%04d %02d:%02d:%02d %s", dabbrev,
- tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_hour, tm->tm_min, (int) rint(sec), tzname[0]);
+ tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_hour, tm->tm_min, (int) rint(sec), CTZName);
} else if (tm->tm_year > 0) {
#if FALSE
sprintf( str, "%3s %3s %02d %02d:%02d:%02d %04d %s", dabbrev,
- mabbrev, tm->tm_mday, tm->tm_hour, tm->tm_min, (int) rint(sec), tm->tm_year, tzname[0]);
+ mabbrev, tm->tm_mday, tm->tm_hour, tm->tm_min, (int) rint(sec), tm->tm_year, CTZName);
#endif
sprintf( str, "%3s %3s %02d %02d:%02d:%5.2f %04d %s", dabbrev,
- mabbrev, tm->tm_mday, tm->tm_hour, tm->tm_min, sec, tm->tm_year, tzname[0]);
+ mabbrev, tm->tm_mday, tm->tm_hour, tm->tm_min, sec, tm->tm_year, CTZName);
/* XXX brute-force fill in leading zero on seconds */
if (*(str+17) == ' ') *(str+17) = '0';
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/nabstime.c,v 1.14 1997/03/14 23:20:31 scrappy Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/nabstime.c,v 1.15 1997/03/18 16:35:20 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
#include <sys/types.h>
#include "postgres.h"
+#include <miscadmin.h>
#ifndef USE_POSIX_TIME
#include <sys/timeb.h>
#endif
#include "access/xact.h"
-#if USE_EURODATES
-extern int EuroDates;
-#endif
-
-#if FALSE
-#define MAXDATELEN 47
-#define MAXDATEFIELDS 25
-#endif
#define MIN_DAYNUM -24856 /* December 13, 1901 */
#define MAX_DAYNUM 24854 /* January 18, 2038 */
-/*
- * parse and convert absolute date in timestr (the normal interface)
+/* GetCurrentAbsoluteTime()
+ * Get the current system time. Set timezone parameters if not specified elsewhere.
+ * Define HasTZSet to allow clients to specify the default timezone.
*
* Returns the number of seconds since epoch (January 1 1970 GMT)
*/
-#ifndef USE_POSIX_TIME
-long int timezone;
-long int daylight;
-#endif
-
AbsoluteTime
GetCurrentAbsoluteTime(void)
{
#ifdef USE_POSIX_TIME
now = time(NULL);
+#else /* ! USE_POSIX_TIME */
+ struct timeb tbnow; /* the old V7-ism */
+
+ (void) ftime(&tbnow);
+ now = tbnow.time;
+#endif
+ if (! HasCTZSet) {
+#ifdef USE_POSIX_TIME
#if defined(HAVE_TZSET) && defined(HAVE_INT_TIMEZONE)
- tzset();
+ tzset();
+ CTimeZone = timezone;
+ CDayLight = daylight;
+ strcpy( CTZName, tzname[0]);
#else /* !HAVE_TZSET */
- struct tm *tmnow = localtime(&now);
+ struct tm *tmnow = localtime(&now);
- timezone = - tmnow->tm_gmtoff; /* tm_gmtoff is Sun/DEC-ism */
- daylight = (tmnow->tm_isdst > 0);
+ 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, "%Z", localtime(&now));
#endif
-
#else /* ! USE_POSIX_TIME */
- struct timeb tbnow; /* the old V7-ism */
-
- (void) ftime(&tbnow);
- now = tbnow.time;
- timezone = tbnow.timezone * 60;
- daylight = (tbnow.dstflag != 0);
+ 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, "%Z", localtime(&now));
#endif
+ };
+
+#ifdef DATEDEBUG
+printf( "GetCurrentAbsoluteTime- timezone is %s -> %d seconds from UTC\n",
+ CTZName, CTimeZone);
+#endif
return((AbsoluteTime) now);
} /* GetCurrentAbsoluteTime() */
/* daylight correction */
if (tm->tm_isdst < 0) { /* unknown; find out */
- tm->tm_isdst = (daylight > 0);
+ tm->tm_isdst = (CDayLight > 0);
};
if (tm->tm_isdst > 0)
sec -= 60*60;
/* daylight correction */
if (tm->tm_isdst < 0) { /* unknown; find out */
- tm->tm_isdst = (daylight > 0);
+ tm->tm_isdst = (CDayLight > 0);
};
if (tm->tm_isdst > 0)
sec -= 60*60;
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/init/globals.c,v 1.5 1997/01/26 15:31:29 scrappy Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/init/globals.c,v 1.6 1997/03/18 16:35:46 scrappy Exp $
*
* NOTES
* Globals used all over the place should be declared here and not
short DebugLvl = 0;
-int EuroDates = 0;
+bool EuroDates = false;
+bool HasCTZSet = false;
+bool CDayLight = false;
+int CTimeZone = 0;
+char CTZName[8] = "";
char *IndexedCatalogNames[] = {
AttributeRelationName,
*
* Copyright (c) 1994, Regents of the University of California
*
- * $Id: miscadmin.h,v 1.5 1997/01/26 15:32:06 scrappy Exp $
+ * $Id: miscadmin.h,v 1.6 1997/03/18 16:36:23 scrappy Exp $
*
* NOTES
* some of the information in this file will be moved to
extern short DebugLvl;
-extern int EuroDates;
+/* Date/Time Configuration
+ * HasCTZSet if client timezone is specified by client.
+ * EuroDates if client prefers dates interpreted and written w/European conventions.
+ * CTimeZone is the timezone offset in seconds.
+ * CTZName is the timezone label.
+ */
+
+extern bool EuroDates;
+extern bool HasCTZSet;
+extern bool CDayLight;
+extern int CTimeZone;
+extern char CTZName[];
extern Oid LastOidProcessed; /* for query rewrite */
*
* Copyright (c) 1994, Regents of the University of California
*
- * $Id: dt.h,v 1.1 1997/03/14 23:33:23 scrappy Exp $
+ * $Id: dt.h,v 1.2 1997/03/18 16:36:50 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
char value; /* this may be unsigned, alas */
} datetkn;
-
-extern int EuroDates;
extern void GetCurrentTime(struct tm *tm);
/*