diff options
| author | Tom Lane | 2005-10-09 17:21:47 +0000 |
|---|---|---|
| committer | Tom Lane | 2005-10-09 17:21:47 +0000 |
| commit | 313ed1ed9498f977262e180a080c7748197ced5c (patch) | |
| tree | 17780e929d9a0d710d84de261b27ac26e9a5adcf /src/include | |
| parent | 7754f7634cbc837702428bbb40a0efbeec7a51d1 (diff) | |
Fix (hopefully for the last time) problems with datetime values displaying
like '23:59:60' because of fractional-second roundoff problems. Trying
to control this upstream of the actual display code was hopeless; the right
way is to explicitly round fractional seconds in the display code and then
refigure the results if the fraction rounds up to 1. Per bug #1927.
Diffstat (limited to 'src/include')
| -rw-r--r-- | src/include/utils/date.h | 6 | ||||
| -rw-r--r-- | src/include/utils/timestamp.h | 9 |
2 files changed, 11 insertions, 4 deletions
diff --git a/src/include/utils/date.h b/src/include/utils/date.h index c3c4a06d871..869e2ade29b 100644 --- a/src/include/utils/date.h +++ b/src/include/utils/date.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/utils/date.h,v 1.30 2005/02/25 16:13:29 teodor Exp $ + * $PostgreSQL: pgsql/src/include/utils/date.h,v 1.31 2005/10/09 17:21:47 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -60,6 +60,10 @@ typedef struct #define MAX_TIME_PRECISION 10 +/* round off to MAX_TIME_PRECISION decimal places */ +#define TIME_PREC_INV 10000000000.0 +#define TIMEROUND(j) (rint(((double) (j)) * TIME_PREC_INV) / TIME_PREC_INV) + #define DatumGetDateADT(X) ((DateADT) DatumGetInt32(X)) #define DatumGetTimeADT(X) ((TimeADT) DatumGetFloat8(X)) #define DatumGetTimeTzADTP(X) ((TimeTzADT *) DatumGetPointer(X)) diff --git a/src/include/utils/timestamp.h b/src/include/utils/timestamp.h index 14c8f6c91b9..dc218f3b28f 100644 --- a/src/include/utils/timestamp.h +++ b/src/include/utils/timestamp.h @@ -6,7 +6,7 @@ * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/utils/timestamp.h,v 1.55 2005/10/07 20:13:16 momjian Exp $ + * $PostgreSQL: pgsql/src/include/utils/timestamp.h,v 1.56 2005/10/09 17:21:47 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -163,8 +163,11 @@ typedef int32 fsec_t; typedef double fsec_t; -#define TIME_PREC_INV 1000000.0 -#define JROUND(j) (rint(((double) (j)) * TIME_PREC_INV) / TIME_PREC_INV) +/* 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 TIMESTAMP_MASK(b) (1 << (b)) |
