mirror of
				https://github.com/postgres/postgres.git
				synced 2025-11-03 09:13:20 +03:00 
			
		
		
		
	Remove now-dead code for !HAVE_INT64_TIMESTAMP.
This is a basically mechanical removal of #ifdef HAVE_INT64_TIMESTAMP tests and the negative-case controlled code. Discussion: https://postgr.es/m/26788.1487455319@sss.pgh.pa.us
This commit is contained in:
		@@ -25,11 +25,7 @@ typedef long long int int64;
 | 
			
		||||
 | 
			
		||||
typedef struct
 | 
			
		||||
{
 | 
			
		||||
#ifdef HAVE_INT64_TIMESTAMP
 | 
			
		||||
	int64		time;			/* all time units other than months and years */
 | 
			
		||||
#else
 | 
			
		||||
	double		time;			/* all time units other than months and years */
 | 
			
		||||
#endif
 | 
			
		||||
	long		month;			/* months and years, after time for alignment */
 | 
			
		||||
}	interval;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -6,13 +6,8 @@
 | 
			
		||||
/* pgtypes_interval.h includes ecpg_config.h */
 | 
			
		||||
#include <pgtypes_interval.h>
 | 
			
		||||
 | 
			
		||||
#ifdef HAVE_INT64_TIMESTAMP
 | 
			
		||||
typedef int64 timestamp;
 | 
			
		||||
typedef int64 TimestampTz;
 | 
			
		||||
#else
 | 
			
		||||
typedef double timestamp;
 | 
			
		||||
typedef double TimestampTz;
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifdef __cplusplus
 | 
			
		||||
extern		"C"
 | 
			
		||||
 
 | 
			
		||||
@@ -37,13 +37,8 @@ PGTYPESdate_from_timestamp(timestamp dt)
 | 
			
		||||
 | 
			
		||||
	if (!TIMESTAMP_NOT_FINITE(dt))
 | 
			
		||||
	{
 | 
			
		||||
#ifdef HAVE_INT64_TIMESTAMP
 | 
			
		||||
		/* Microseconds to days */
 | 
			
		||||
		dDate = (dt / USECS_PER_DAY);
 | 
			
		||||
#else
 | 
			
		||||
		/* Seconds to days */
 | 
			
		||||
		dDate = (dt / (double) SECS_PER_DAY);
 | 
			
		||||
#endif
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return dDate;
 | 
			
		||||
 
 | 
			
		||||
@@ -7,18 +7,7 @@
 | 
			
		||||
 | 
			
		||||
#define MAXTZLEN			 10
 | 
			
		||||
 | 
			
		||||
#ifdef HAVE_INT64_TIMESTAMP
 | 
			
		||||
 | 
			
		||||
typedef int32 fsec_t;
 | 
			
		||||
#else
 | 
			
		||||
 | 
			
		||||
typedef double fsec_t;
 | 
			
		||||
 | 
			
		||||
/* round off to MAX_TIMESTAMP_PRECISION decimal places */
 | 
			
		||||
/* note: this is also used for rounding off intervals */
 | 
			
		||||
#define TS_PREC_INV 1000000.0
 | 
			
		||||
#define TSROUND(j) (rint(((double) (j)) * TS_PREC_INV) / TS_PREC_INV)
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#define USE_POSTGRES_DATES				0
 | 
			
		||||
#define USE_ISO_DATES					1
 | 
			
		||||
@@ -232,23 +221,15 @@ do { \
 | 
			
		||||
} while(0)
 | 
			
		||||
 | 
			
		||||
/* TMODULO()
 | 
			
		||||
 * Like FMODULO(), but work on the timestamp datatype (either int64 or float8).
 | 
			
		||||
 * Like FMODULO(), but work on the timestamp datatype (now always int64).
 | 
			
		||||
 * We assume that int64 follows the C99 semantics for division (negative
 | 
			
		||||
 * quotients truncate towards zero).
 | 
			
		||||
 */
 | 
			
		||||
#ifdef HAVE_INT64_TIMESTAMP
 | 
			
		||||
#define TMODULO(t,q,u) \
 | 
			
		||||
do { \
 | 
			
		||||
	(q) = ((t) / (u)); \
 | 
			
		||||
	if ((q) != 0) (t) -= ((q) * (u)); \
 | 
			
		||||
} while(0)
 | 
			
		||||
#else
 | 
			
		||||
#define TMODULO(t,q,u) \
 | 
			
		||||
do { \
 | 
			
		||||
	(q) = (((t) < 0) ? ceil((t) / (u)): floor((t) / (u))); \
 | 
			
		||||
	if ((q) != 0) (t) -= rint((q) * (u)); \
 | 
			
		||||
} while(0)
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
/* in both timestamp.h and ecpg/dt.h */
 | 
			
		||||
#define DAYS_PER_YEAR	365.25	/* assumes leap year every four years */
 | 
			
		||||
@@ -274,12 +255,10 @@ do { \
 | 
			
		||||
#define SECS_PER_MINUTE 60
 | 
			
		||||
#define MINS_PER_HOUR	60
 | 
			
		||||
 | 
			
		||||
#ifdef HAVE_INT64_TIMESTAMP
 | 
			
		||||
#define USECS_PER_DAY	INT64CONST(86400000000)
 | 
			
		||||
#define USECS_PER_HOUR	INT64CONST(3600000000)
 | 
			
		||||
#define USECS_PER_MINUTE INT64CONST(60000000)
 | 
			
		||||
#define USECS_PER_SEC	INT64CONST(1000000)
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Date/time validation
 | 
			
		||||
@@ -304,13 +283,8 @@ do { \
 | 
			
		||||
	 ((y) < JULIAN_MAXYEAR || \
 | 
			
		||||
	  ((y) == JULIAN_MAXYEAR && ((m) < JULIAN_MAXMONTH))))
 | 
			
		||||
 | 
			
		||||
#ifdef HAVE_INT64_TIMESTAMP
 | 
			
		||||
#define MIN_TIMESTAMP	INT64CONST(-211813488000000000)
 | 
			
		||||
#define END_TIMESTAMP	INT64CONST(9223371331200000000)
 | 
			
		||||
#else
 | 
			
		||||
#define MIN_TIMESTAMP	(-211813488000.0)
 | 
			
		||||
#define END_TIMESTAMP	185330760393600.0
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#define IS_VALID_TIMESTAMP(t)  (MIN_TIMESTAMP <= (t) && (t) < END_TIMESTAMP)
 | 
			
		||||
 | 
			
		||||
@@ -328,20 +302,8 @@ do { \
 | 
			
		||||
 || (((y) == UTIME_MAXYEAR) && (((m) < UTIME_MAXMONTH) \
 | 
			
		||||
  || (((m) == UTIME_MAXMONTH) && ((d) <= UTIME_MAXDAY))))))
 | 
			
		||||
 | 
			
		||||
#ifdef HAVE_INT64_TIMESTAMP
 | 
			
		||||
 | 
			
		||||
#define DT_NOBEGIN		(-INT64CONST(0x7fffffffffffffff) - 1)
 | 
			
		||||
#define DT_NOEND		(INT64CONST(0x7fffffffffffffff))
 | 
			
		||||
#else
 | 
			
		||||
 | 
			
		||||
#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
 | 
			
		||||
#endif   /* HAVE_INT64_TIMESTAMP */
 | 
			
		||||
 | 
			
		||||
#define TIMESTAMP_NOBEGIN(j)	do {(j) = DT_NOBEGIN;} while (0)
 | 
			
		||||
#define TIMESTAMP_NOEND(j)			do {(j) = DT_NOEND;} while (0)
 | 
			
		||||
 
 | 
			
		||||
@@ -783,19 +783,10 @@ EncodeDateTime(struct tm * tm, fsec_t fsec, bool print_tz, int tz, const char *t
 | 
			
		||||
			/*
 | 
			
		||||
			 * Print fractional seconds if any.  The field widths here should
 | 
			
		||||
			 * be at least equal to MAX_TIMESTAMP_PRECISION.
 | 
			
		||||
			 *
 | 
			
		||||
			 * In float mode, don't print fractional seconds before 1 AD,
 | 
			
		||||
			 * since it's unlikely there's any precision left ...
 | 
			
		||||
			 */
 | 
			
		||||
#ifdef HAVE_INT64_TIMESTAMP
 | 
			
		||||
			if (fsec != 0)
 | 
			
		||||
			{
 | 
			
		||||
				sprintf(str + strlen(str), ":%02d.%06d", tm->tm_sec, fsec);
 | 
			
		||||
#else
 | 
			
		||||
			if ((fsec != 0) && (tm->tm_year > 0))
 | 
			
		||||
			{
 | 
			
		||||
				sprintf(str + strlen(str), ":%09.6f", tm->tm_sec + fsec);
 | 
			
		||||
#endif
 | 
			
		||||
				TrimTrailingZeros(str);
 | 
			
		||||
			}
 | 
			
		||||
			else
 | 
			
		||||
@@ -830,19 +821,10 @@ EncodeDateTime(struct tm * tm, fsec_t fsec, bool print_tz, int tz, const char *t
 | 
			
		||||
			/*
 | 
			
		||||
			 * Print fractional seconds if any.  The field widths here should
 | 
			
		||||
			 * be at least equal to MAX_TIMESTAMP_PRECISION.
 | 
			
		||||
			 *
 | 
			
		||||
			 * In float mode, don't print fractional seconds before 1 AD,
 | 
			
		||||
			 * since it's unlikely there's any precision left ...
 | 
			
		||||
			 */
 | 
			
		||||
#ifdef HAVE_INT64_TIMESTAMP
 | 
			
		||||
			if (fsec != 0)
 | 
			
		||||
			{
 | 
			
		||||
				sprintf(str + strlen(str), ":%02d.%06d", tm->tm_sec, fsec);
 | 
			
		||||
#else
 | 
			
		||||
			if (fsec != 0 && tm->tm_year > 0)
 | 
			
		||||
			{
 | 
			
		||||
				sprintf(str + strlen(str), ":%09.6f", tm->tm_sec + fsec);
 | 
			
		||||
#endif
 | 
			
		||||
				TrimTrailingZeros(str);
 | 
			
		||||
			}
 | 
			
		||||
			else
 | 
			
		||||
@@ -885,19 +867,10 @@ EncodeDateTime(struct tm * tm, fsec_t fsec, bool print_tz, int tz, const char *t
 | 
			
		||||
			/*
 | 
			
		||||
			 * Print fractional seconds if any.  The field widths here should
 | 
			
		||||
			 * be at least equal to MAX_TIMESTAMP_PRECISION.
 | 
			
		||||
			 *
 | 
			
		||||
			 * In float mode, don't print fractional seconds before 1 AD,
 | 
			
		||||
			 * since it's unlikely there's any precision left ...
 | 
			
		||||
			 */
 | 
			
		||||
#ifdef HAVE_INT64_TIMESTAMP
 | 
			
		||||
			if (fsec != 0)
 | 
			
		||||
			{
 | 
			
		||||
				sprintf(str + strlen(str), ":%02d.%06d", tm->tm_sec, fsec);
 | 
			
		||||
#else
 | 
			
		||||
			if (fsec != 0 && tm->tm_year > 0)
 | 
			
		||||
			{
 | 
			
		||||
				sprintf(str + strlen(str), ":%09.6f", tm->tm_sec + fsec);
 | 
			
		||||
#endif
 | 
			
		||||
				TrimTrailingZeros(str);
 | 
			
		||||
			}
 | 
			
		||||
			else
 | 
			
		||||
@@ -942,19 +915,10 @@ EncodeDateTime(struct tm * tm, fsec_t fsec, bool print_tz, int tz, const char *t
 | 
			
		||||
			/*
 | 
			
		||||
			 * Print fractional seconds if any.  The field widths here should
 | 
			
		||||
			 * be at least equal to MAX_TIMESTAMP_PRECISION.
 | 
			
		||||
			 *
 | 
			
		||||
			 * In float mode, don't print fractional seconds before 1 AD,
 | 
			
		||||
			 * since it's unlikely there's any precision left ...
 | 
			
		||||
			 */
 | 
			
		||||
#ifdef HAVE_INT64_TIMESTAMP
 | 
			
		||||
			if (fsec != 0)
 | 
			
		||||
			{
 | 
			
		||||
				sprintf(str + strlen(str), ":%02d.%06d", tm->tm_sec, fsec);
 | 
			
		||||
#else
 | 
			
		||||
			if (fsec != 0 && tm->tm_year > 0)
 | 
			
		||||
			{
 | 
			
		||||
				sprintf(str + strlen(str), ":%09.6f", tm->tm_sec + fsec);
 | 
			
		||||
#endif
 | 
			
		||||
				TrimTrailingZeros(str);
 | 
			
		||||
			}
 | 
			
		||||
			else
 | 
			
		||||
@@ -1110,28 +1074,15 @@ GetCurrentDateTime(struct tm * tm)
 | 
			
		||||
void
 | 
			
		||||
dt2time(double jd, int *hour, int *min, int *sec, fsec_t *fsec)
 | 
			
		||||
{
 | 
			
		||||
#ifdef HAVE_INT64_TIMESTAMP
 | 
			
		||||
	int64		time;
 | 
			
		||||
#else
 | 
			
		||||
	double		time;
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
	time = jd;
 | 
			
		||||
#ifdef HAVE_INT64_TIMESTAMP
 | 
			
		||||
	*hour = time / USECS_PER_HOUR;
 | 
			
		||||
	time -= (*hour) * USECS_PER_HOUR;
 | 
			
		||||
	*min = time / USECS_PER_MINUTE;
 | 
			
		||||
	time -= (*min) * USECS_PER_MINUTE;
 | 
			
		||||
	*sec = time / USECS_PER_SEC;
 | 
			
		||||
	*fsec = time - (*sec * USECS_PER_SEC);
 | 
			
		||||
#else
 | 
			
		||||
	*hour = time / SECS_PER_HOUR;
 | 
			
		||||
	time -= (*hour) * SECS_PER_HOUR;
 | 
			
		||||
	*min = time / SECS_PER_MINUTE;
 | 
			
		||||
	time -= (*min) * SECS_PER_MINUTE;
 | 
			
		||||
	*sec = time;
 | 
			
		||||
	*fsec = time - *sec;
 | 
			
		||||
#endif
 | 
			
		||||
}	/* dt2time() */
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -1153,7 +1104,6 @@ DecodeNumberField(int len, char *str, int fmask,
 | 
			
		||||
	 */
 | 
			
		||||
	if ((cp = strchr(str, '.')) != NULL)
 | 
			
		||||
	{
 | 
			
		||||
#ifdef HAVE_INT64_TIMESTAMP
 | 
			
		||||
		char		fstr[7];
 | 
			
		||||
		int			i;
 | 
			
		||||
 | 
			
		||||
@@ -1164,16 +1114,13 @@ DecodeNumberField(int len, char *str, int fmask,
 | 
			
		||||
		 * string with those digits, zero-padded on the right, and then do the
 | 
			
		||||
		 * conversion to an integer.
 | 
			
		||||
		 *
 | 
			
		||||
		 * XXX This truncates the seventh digit, unlike rounding it as do the
 | 
			
		||||
		 * backend and the !HAVE_INT64_TIMESTAMP case.
 | 
			
		||||
		 * XXX This truncates the seventh digit, unlike rounding it as the
 | 
			
		||||
		 * backend does.
 | 
			
		||||
		 */
 | 
			
		||||
		for (i = 0; i < 6; i++)
 | 
			
		||||
			fstr[i] = *cp != '\0' ? *cp++ : '0';
 | 
			
		||||
		fstr[i] = '\0';
 | 
			
		||||
		*fsec = strtol(fstr, NULL, 10);
 | 
			
		||||
#else
 | 
			
		||||
		*fsec = strtod(cp, NULL);
 | 
			
		||||
#endif
 | 
			
		||||
		*cp = '\0';
 | 
			
		||||
		len = strlen(str);
 | 
			
		||||
	}
 | 
			
		||||
@@ -1520,7 +1467,6 @@ DecodeTime(char *str, int *tmask, struct tm * tm, fsec_t *fsec)
 | 
			
		||||
			*fsec = 0;
 | 
			
		||||
		else if (*cp == '.')
 | 
			
		||||
		{
 | 
			
		||||
#ifdef HAVE_INT64_TIMESTAMP
 | 
			
		||||
			char		fstr[7];
 | 
			
		||||
			int			i;
 | 
			
		||||
 | 
			
		||||
@@ -1531,17 +1477,13 @@ DecodeTime(char *str, int *tmask, struct tm * tm, fsec_t *fsec)
 | 
			
		||||
			 * string with those digits, zero-padded on the right, and then do
 | 
			
		||||
			 * the conversion to an integer.
 | 
			
		||||
			 *
 | 
			
		||||
			 * XXX This truncates the seventh digit, unlike rounding it as do
 | 
			
		||||
			 * the backend and the !HAVE_INT64_TIMESTAMP case.
 | 
			
		||||
			 * XXX This truncates the seventh digit, unlike rounding it as the
 | 
			
		||||
			 * backend does.
 | 
			
		||||
			 */
 | 
			
		||||
			for (i = 0; i < 6; i++)
 | 
			
		||||
				fstr[i] = *cp != '\0' ? *cp++ : '0';
 | 
			
		||||
			fstr[i] = '\0';
 | 
			
		||||
			*fsec = strtol(fstr, &cp, 10);
 | 
			
		||||
#else
 | 
			
		||||
			str = cp;
 | 
			
		||||
			*fsec = strtod(str, &cp);
 | 
			
		||||
#endif
 | 
			
		||||
			if (*cp != '\0')
 | 
			
		||||
				return -1;
 | 
			
		||||
		}
 | 
			
		||||
@@ -1550,15 +1492,9 @@ DecodeTime(char *str, int *tmask, struct tm * tm, fsec_t *fsec)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/* do a sanity check */
 | 
			
		||||
#ifdef HAVE_INT64_TIMESTAMP
 | 
			
		||||
	if (tm->tm_hour < 0 || tm->tm_min < 0 || tm->tm_min > 59 ||
 | 
			
		||||
		tm->tm_sec < 0 || tm->tm_sec > 59 || *fsec >= USECS_PER_SEC)
 | 
			
		||||
		return -1;
 | 
			
		||||
#else
 | 
			
		||||
	if (tm->tm_hour < 0 || tm->tm_min < 0 || tm->tm_min > 59 ||
 | 
			
		||||
		tm->tm_sec < 0 || tm->tm_sec > 59 || *fsec >= 1)
 | 
			
		||||
		return -1;
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
	return 0;
 | 
			
		||||
}	/* DecodeTime() */
 | 
			
		||||
@@ -2105,11 +2041,7 @@ DecodeDateTime(char **field, int *ftype, int nf,
 | 
			
		||||
								frac = strtod(cp, &cp);
 | 
			
		||||
								if (*cp != '\0')
 | 
			
		||||
									return -1;
 | 
			
		||||
#ifdef HAVE_INT64_TIMESTAMP
 | 
			
		||||
								*fsec = frac * 1000000;
 | 
			
		||||
#else
 | 
			
		||||
								*fsec = frac;
 | 
			
		||||
#endif
 | 
			
		||||
							}
 | 
			
		||||
							break;
 | 
			
		||||
 | 
			
		||||
@@ -2135,11 +2067,7 @@ DecodeDateTime(char **field, int *ftype, int nf,
 | 
			
		||||
									return -1;
 | 
			
		||||
 | 
			
		||||
								tmask |= DTK_TIME_M;
 | 
			
		||||
#ifdef HAVE_INT64_TIMESTAMP
 | 
			
		||||
								dt2time((time * USECS_PER_DAY), &tm->tm_hour, &tm->tm_min, &tm->tm_sec, fsec);
 | 
			
		||||
#else
 | 
			
		||||
								dt2time((time * SECS_PER_DAY), &tm->tm_hour, &tm->tm_min, &tm->tm_sec, fsec);
 | 
			
		||||
#endif
 | 
			
		||||
							}
 | 
			
		||||
							break;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -42,11 +42,7 @@ AdjustFractSeconds(double frac, struct /* pg_ */ tm * tm, fsec_t *fsec, int scal
 | 
			
		||||
	sec = (int) frac;
 | 
			
		||||
	tm->tm_sec += sec;
 | 
			
		||||
	frac -= sec;
 | 
			
		||||
#ifdef HAVE_INT64_TIMESTAMP
 | 
			
		||||
	*fsec += rint(frac * 1000000);
 | 
			
		||||
#else
 | 
			
		||||
	*fsec += frac;
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -488,30 +484,18 @@ DecodeInterval(char **field, int *ftype, int nf,		/* int range, */
 | 
			
		||||
				switch (type)
 | 
			
		||||
				{
 | 
			
		||||
					case DTK_MICROSEC:
 | 
			
		||||
#ifdef HAVE_INT64_TIMESTAMP
 | 
			
		||||
						*fsec += rint(val + fval);
 | 
			
		||||
#else
 | 
			
		||||
						*fsec += (val + fval) * 1e-6;
 | 
			
		||||
#endif
 | 
			
		||||
						tmask = DTK_M(MICROSECOND);
 | 
			
		||||
						break;
 | 
			
		||||
 | 
			
		||||
					case DTK_MILLISEC:
 | 
			
		||||
#ifdef HAVE_INT64_TIMESTAMP
 | 
			
		||||
						*fsec += rint((val + fval) * 1000);
 | 
			
		||||
#else
 | 
			
		||||
						*fsec += (val + fval) * 1e-3;
 | 
			
		||||
#endif
 | 
			
		||||
						tmask = DTK_M(MILLISECOND);
 | 
			
		||||
						break;
 | 
			
		||||
 | 
			
		||||
					case DTK_SECOND:
 | 
			
		||||
						tm->tm_sec += val;
 | 
			
		||||
#ifdef HAVE_INT64_TIMESTAMP
 | 
			
		||||
						*fsec += rint(fval * 1000000);
 | 
			
		||||
#else
 | 
			
		||||
						*fsec += fval;
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
						/*
 | 
			
		||||
						 * If any subseconds were specified, consider this
 | 
			
		||||
@@ -633,12 +617,8 @@ DecodeInterval(char **field, int *ftype, int nf,		/* int range, */
 | 
			
		||||
	{
 | 
			
		||||
		int			sec;
 | 
			
		||||
 | 
			
		||||
#ifdef HAVE_INT64_TIMESTAMP
 | 
			
		||||
		sec = *fsec / USECS_PER_SEC;
 | 
			
		||||
		*fsec -= sec * USECS_PER_SEC;
 | 
			
		||||
#else
 | 
			
		||||
		TMODULO(*fsec, sec, 1.0);
 | 
			
		||||
#endif
 | 
			
		||||
		tm->tm_sec += sec;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@@ -777,17 +757,10 @@ AppendSeconds(char *cp, int sec, fsec_t fsec, int precision, bool fillzeros)
 | 
			
		||||
	}
 | 
			
		||||
	else
 | 
			
		||||
	{
 | 
			
		||||
#ifdef HAVE_INT64_TIMESTAMP
 | 
			
		||||
		if (fillzeros)
 | 
			
		||||
			sprintf(cp, "%02d.%0*d", abs(sec), precision, (int) Abs(fsec));
 | 
			
		||||
		else
 | 
			
		||||
			sprintf(cp, "%d.%0*d", abs(sec), precision, (int) Abs(fsec));
 | 
			
		||||
#else
 | 
			
		||||
		if (fillzeros)
 | 
			
		||||
			sprintf(cp, "%0*.*f", precision + 3, precision, fabs(sec + fsec));
 | 
			
		||||
		else
 | 
			
		||||
			sprintf(cp, "%.*f", precision, fabs(sec + fsec));
 | 
			
		||||
#endif
 | 
			
		||||
		TrimTrailingZeros(cp);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@@ -985,11 +958,7 @@ EncodeInterval(struct /* pg_ */ tm * tm, fsec_t fsec, int style, char *str)
 | 
			
		||||
static int
 | 
			
		||||
interval2tm(interval span, struct tm * tm, fsec_t *fsec)
 | 
			
		||||
{
 | 
			
		||||
#ifdef HAVE_INT64_TIMESTAMP
 | 
			
		||||
	int64		time;
 | 
			
		||||
#else
 | 
			
		||||
	double		time;
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
	if (span.month != 0)
 | 
			
		||||
	{
 | 
			
		||||
@@ -1005,7 +974,6 @@ interval2tm(interval span, struct tm * tm, fsec_t *fsec)
 | 
			
		||||
 | 
			
		||||
	time = span.time;
 | 
			
		||||
 | 
			
		||||
#ifdef HAVE_INT64_TIMESTAMP
 | 
			
		||||
	tm->tm_mday = time / USECS_PER_DAY;
 | 
			
		||||
	time -= tm->tm_mday * USECS_PER_DAY;
 | 
			
		||||
	tm->tm_hour = time / USECS_PER_HOUR;
 | 
			
		||||
@@ -1014,21 +982,6 @@ interval2tm(interval span, struct tm * tm, fsec_t *fsec)
 | 
			
		||||
	time -= tm->tm_min * USECS_PER_MINUTE;
 | 
			
		||||
	tm->tm_sec = time / USECS_PER_SEC;
 | 
			
		||||
	*fsec = time - (tm->tm_sec * USECS_PER_SEC);
 | 
			
		||||
#else
 | 
			
		||||
recalc:
 | 
			
		||||
	TMODULO(time, tm->tm_mday, (double) SECS_PER_DAY);
 | 
			
		||||
	TMODULO(time, tm->tm_hour, (double) SECS_PER_HOUR);
 | 
			
		||||
	TMODULO(time, tm->tm_min, (double) SECS_PER_MINUTE);
 | 
			
		||||
	TMODULO(time, tm->tm_sec, 1.0);
 | 
			
		||||
	time = TSROUND(time);
 | 
			
		||||
	/* roundoff may need to propagate to higher-order fields */
 | 
			
		||||
	if (time >= 1.0)
 | 
			
		||||
	{
 | 
			
		||||
		time = ceil(span.time);
 | 
			
		||||
		goto recalc;
 | 
			
		||||
	}
 | 
			
		||||
	*fsec = time;
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
	return 0;
 | 
			
		||||
}	/* interval2tm() */
 | 
			
		||||
@@ -1040,17 +993,10 @@ tm2interval(struct tm * tm, fsec_t fsec, interval * span)
 | 
			
		||||
		(double) tm->tm_year * MONTHS_PER_YEAR + tm->tm_mon < INT_MIN)
 | 
			
		||||
		return -1;
 | 
			
		||||
	span->month = tm->tm_year * MONTHS_PER_YEAR + tm->tm_mon;
 | 
			
		||||
#ifdef HAVE_INT64_TIMESTAMP
 | 
			
		||||
	span->time = (((((((tm->tm_mday * INT64CONST(24)) +
 | 
			
		||||
					   tm->tm_hour) * INT64CONST(60)) +
 | 
			
		||||
					 tm->tm_min) * INT64CONST(60)) +
 | 
			
		||||
				   tm->tm_sec) * USECS_PER_SEC) + fsec;
 | 
			
		||||
#else
 | 
			
		||||
	span->time = (((((tm->tm_mday * (double) HOURS_PER_DAY) +
 | 
			
		||||
					 tm->tm_hour) * (double) MINS_PER_HOUR) +
 | 
			
		||||
				   tm->tm_min) * (double) SECS_PER_MINUTE) +
 | 
			
		||||
		tm->tm_sec + fsec;
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
	return 0;
 | 
			
		||||
}	/* tm2interval() */
 | 
			
		||||
 
 | 
			
		||||
@@ -18,28 +18,16 @@
 | 
			
		||||
#include "pgtypes_date.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#ifdef HAVE_INT64_TIMESTAMP
 | 
			
		||||
static int64
 | 
			
		||||
time2t(const int hour, const int min, const int sec, const fsec_t fsec)
 | 
			
		||||
{
 | 
			
		||||
	return (((((hour * MINS_PER_HOUR) + min) * SECS_PER_MINUTE) + sec) * USECS_PER_SEC) + fsec;
 | 
			
		||||
}	/* time2t() */
 | 
			
		||||
#else
 | 
			
		||||
static double
 | 
			
		||||
time2t(const int hour, const int min, const int sec, const fsec_t fsec)
 | 
			
		||||
{
 | 
			
		||||
	return (((hour * MINS_PER_HOUR) + min) * SECS_PER_MINUTE) + sec + fsec;
 | 
			
		||||
}	/* time2t() */
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
static timestamp
 | 
			
		||||
dt2local(timestamp dt, int tz)
 | 
			
		||||
{
 | 
			
		||||
#ifdef HAVE_INT64_TIMESTAMP
 | 
			
		||||
	dt -= (tz * USECS_PER_SEC);
 | 
			
		||||
#else
 | 
			
		||||
	dt -= tz;
 | 
			
		||||
#endif
 | 
			
		||||
	return dt;
 | 
			
		||||
}	/* dt2local() */
 | 
			
		||||
 | 
			
		||||
@@ -53,13 +41,8 @@ dt2local(timestamp dt, int tz)
 | 
			
		||||
int
 | 
			
		||||
tm2timestamp(struct tm * tm, fsec_t fsec, int *tzp, timestamp * result)
 | 
			
		||||
{
 | 
			
		||||
#ifdef HAVE_INT64_TIMESTAMP
 | 
			
		||||
	int			dDate;
 | 
			
		||||
	int64		time;
 | 
			
		||||
#else
 | 
			
		||||
	double		dDate,
 | 
			
		||||
				time;
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
	/* Prevent overflow in Julian-day routines */
 | 
			
		||||
	if (!IS_VALID_JULIAN(tm->tm_year, tm->tm_mon, tm->tm_mday))
 | 
			
		||||
@@ -67,7 +50,6 @@ tm2timestamp(struct tm * tm, fsec_t fsec, int *tzp, timestamp * result)
 | 
			
		||||
 | 
			
		||||
	dDate = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) - date2j(2000, 1, 1);
 | 
			
		||||
	time = time2t(tm->tm_hour, tm->tm_min, tm->tm_sec, fsec);
 | 
			
		||||
#ifdef HAVE_INT64_TIMESTAMP
 | 
			
		||||
	*result = (dDate * USECS_PER_DAY) + time;
 | 
			
		||||
	/* check for major overflow */
 | 
			
		||||
	if ((*result - time) / USECS_PER_DAY != dDate)
 | 
			
		||||
@@ -77,9 +59,6 @@ tm2timestamp(struct tm * tm, fsec_t fsec, int *tzp, timestamp * result)
 | 
			
		||||
	if ((*result < 0 && dDate > 0) ||
 | 
			
		||||
		(*result > 0 && dDate < -1))
 | 
			
		||||
		return -1;
 | 
			
		||||
#else
 | 
			
		||||
	*result = dDate * SECS_PER_DAY + time;
 | 
			
		||||
#endif
 | 
			
		||||
	if (tzp != NULL)
 | 
			
		||||
		*result = dt2local(*result, -(*tzp));
 | 
			
		||||
 | 
			
		||||
@@ -93,11 +72,7 @@ tm2timestamp(struct tm * tm, fsec_t fsec, int *tzp, timestamp * result)
 | 
			
		||||
static timestamp
 | 
			
		||||
SetEpochTimestamp(void)
 | 
			
		||||
{
 | 
			
		||||
#ifdef HAVE_INT64_TIMESTAMP
 | 
			
		||||
	int64		noresult = 0;
 | 
			
		||||
#else
 | 
			
		||||
	double		noresult = 0.0;
 | 
			
		||||
#endif
 | 
			
		||||
	timestamp	dt;
 | 
			
		||||
	struct tm	tt,
 | 
			
		||||
			   *tm = &tt;
 | 
			
		||||
@@ -123,15 +98,9 @@ SetEpochTimestamp(void)
 | 
			
		||||
static int
 | 
			
		||||
timestamp2tm(timestamp dt, int *tzp, struct tm * tm, fsec_t *fsec, const char **tzn)
 | 
			
		||||
{
 | 
			
		||||
#ifdef HAVE_INT64_TIMESTAMP
 | 
			
		||||
	int64		dDate,
 | 
			
		||||
				date0;
 | 
			
		||||
	int64		time;
 | 
			
		||||
#else
 | 
			
		||||
	double		dDate,
 | 
			
		||||
				date0;
 | 
			
		||||
	double		time;
 | 
			
		||||
#endif
 | 
			
		||||
#if defined(HAVE_TM_ZONE) || defined(HAVE_INT_TIMEZONE)
 | 
			
		||||
	time_t		utime;
 | 
			
		||||
	struct tm  *tx;
 | 
			
		||||
@@ -139,7 +108,6 @@ timestamp2tm(timestamp dt, int *tzp, struct tm * tm, fsec_t *fsec, const char **
 | 
			
		||||
 | 
			
		||||
	date0 = date2j(2000, 1, 1);
 | 
			
		||||
 | 
			
		||||
#ifdef HAVE_INT64_TIMESTAMP
 | 
			
		||||
	time = dt;
 | 
			
		||||
	TMODULO(time, dDate, USECS_PER_DAY);
 | 
			
		||||
 | 
			
		||||
@@ -158,42 +126,6 @@ timestamp2tm(timestamp dt, int *tzp, struct tm * tm, fsec_t *fsec, const char **
 | 
			
		||||
 | 
			
		||||
	j2date((int) dDate, &tm->tm_year, &tm->tm_mon, &tm->tm_mday);
 | 
			
		||||
	dt2time(time, &tm->tm_hour, &tm->tm_min, &tm->tm_sec, fsec);
 | 
			
		||||
#else
 | 
			
		||||
	time = dt;
 | 
			
		||||
	TMODULO(time, dDate, (double) SECS_PER_DAY);
 | 
			
		||||
 | 
			
		||||
	if (time < 0)
 | 
			
		||||
	{
 | 
			
		||||
		time += SECS_PER_DAY;
 | 
			
		||||
		dDate -= 1;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/* add offset to go from J2000 back to standard Julian date */
 | 
			
		||||
	dDate += date0;
 | 
			
		||||
 | 
			
		||||
recalc_d:
 | 
			
		||||
	/* Julian day routine does not work for negative Julian days */
 | 
			
		||||
	if (dDate < 0 || dDate > (timestamp) INT_MAX)
 | 
			
		||||
		return -1;
 | 
			
		||||
 | 
			
		||||
	j2date((int) dDate, &tm->tm_year, &tm->tm_mon, &tm->tm_mday);
 | 
			
		||||
recalc_t:
 | 
			
		||||
	dt2time(time, &tm->tm_hour, &tm->tm_min, &tm->tm_sec, fsec);
 | 
			
		||||
 | 
			
		||||
	*fsec = TSROUND(*fsec);
 | 
			
		||||
	/* roundoff may need to propagate to higher-order fields */
 | 
			
		||||
	if (*fsec >= 1.0)
 | 
			
		||||
	{
 | 
			
		||||
		time = ceil(time);
 | 
			
		||||
		if (time >= (double) SECS_PER_DAY)
 | 
			
		||||
		{
 | 
			
		||||
			time = 0;
 | 
			
		||||
			dDate += 1;
 | 
			
		||||
			goto recalc_d;
 | 
			
		||||
		}
 | 
			
		||||
		goto recalc_t;
 | 
			
		||||
	}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
	if (tzp != NULL)
 | 
			
		||||
	{
 | 
			
		||||
@@ -205,12 +137,8 @@ recalc_t:
 | 
			
		||||
		{
 | 
			
		||||
#if defined(HAVE_TM_ZONE) || defined(HAVE_INT_TIMEZONE)
 | 
			
		||||
 | 
			
		||||
#ifdef HAVE_INT64_TIMESTAMP
 | 
			
		||||
			utime = dt / USECS_PER_SEC +
 | 
			
		||||
				((date0 - date2j(1970, 1, 1)) * INT64CONST(86400));
 | 
			
		||||
#else
 | 
			
		||||
			utime = dt + (date0 - date2j(1970, 1, 1)) * SECS_PER_DAY;
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
			tx = localtime(&utime);
 | 
			
		||||
			tm->tm_year = tx->tm_year + 1900;
 | 
			
		||||
@@ -281,12 +209,7 @@ timestamp
 | 
			
		||||
PGTYPEStimestamp_from_asc(char *str, char **endptr)
 | 
			
		||||
{
 | 
			
		||||
	timestamp	result;
 | 
			
		||||
 | 
			
		||||
#ifdef HAVE_INT64_TIMESTAMP
 | 
			
		||||
	int64		noresult = 0;
 | 
			
		||||
#else
 | 
			
		||||
	double		noresult = 0.0;
 | 
			
		||||
#endif
 | 
			
		||||
	fsec_t		fsec;
 | 
			
		||||
	struct tm	tt,
 | 
			
		||||
			   *tm = &tt;
 | 
			
		||||
@@ -633,13 +556,8 @@ dttofmtasc_replace(timestamp * ts, date dDate, int dow, struct tm * tm,
 | 
			
		||||
					break;
 | 
			
		||||
					/* The number of seconds since the Epoch (1970-01-01) */
 | 
			
		||||
				case 's':
 | 
			
		||||
#ifdef HAVE_INT64_TIMESTAMP
 | 
			
		||||
					replace_val.int64_val = (*ts - SetEpochTimestamp()) / 1000000.0;
 | 
			
		||||
					replace_type = PGTYPES_TYPE_INT64;
 | 
			
		||||
#else
 | 
			
		||||
					replace_val.double_val = *ts - SetEpochTimestamp();
 | 
			
		||||
					replace_type = PGTYPES_TYPE_DOUBLE_NF;
 | 
			
		||||
#endif
 | 
			
		||||
					break;
 | 
			
		||||
					/* seconds as a decimal number with leading zeroes */
 | 
			
		||||
				case 'S':
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user