Skip to content

Commit 47386fe

Browse files
committed
Use floor() not rint() when reducing precision of fractional seconds in
timestamp_trunc, timestamptz_trunc, and interval_trunc(). This change only affects the float-datetime case; the integer-datetime case already behaved like truncation instead of rounding. Per gripe from Mario Splivalo. This is a pre-existing issue but I'm choosing not to backpatch, because it's such a corner case and there have not been prior complaints. The issue is largely moot anyway given the trend towards integer datetimes.
1 parent 44886bd commit 47386fe

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/backend/utils/adt/timestamp.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.201 2009/06/11 14:49:04 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.202 2009/07/06 20:29:23 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -3338,13 +3338,13 @@ timestamp_trunc(PG_FUNCTION_ARGS)
33383338
#ifdef HAVE_INT64_TIMESTAMP
33393339
fsec = (fsec / 1000) * 1000;
33403340
#else
3341-
fsec = rint(fsec * 1000) / 1000;
3341+
fsec = floor(fsec * 1000) / 1000;
33423342
#endif
33433343
break;
33443344

33453345
case DTK_MICROSEC:
33463346
#ifndef HAVE_INT64_TIMESTAMP
3347-
fsec = rint(fsec * 1000000) / 1000000;
3347+
fsec = floor(fsec * 1000000) / 1000000;
33483348
#endif
33493349
break;
33503350

@@ -3494,12 +3494,12 @@ timestamptz_trunc(PG_FUNCTION_ARGS)
34943494
#ifdef HAVE_INT64_TIMESTAMP
34953495
fsec = (fsec / 1000) * 1000;
34963496
#else
3497-
fsec = rint(fsec * 1000) / 1000;
3497+
fsec = floor(fsec * 1000) / 1000;
34983498
#endif
34993499
break;
35003500
case DTK_MICROSEC:
35013501
#ifndef HAVE_INT64_TIMESTAMP
3502-
fsec = rint(fsec * 1000000) / 1000000;
3502+
fsec = floor(fsec * 1000000) / 1000000;
35033503
#endif
35043504
break;
35053505

@@ -3591,12 +3591,12 @@ interval_trunc(PG_FUNCTION_ARGS)
35913591
#ifdef HAVE_INT64_TIMESTAMP
35923592
fsec = (fsec / 1000) * 1000;
35933593
#else
3594-
fsec = rint(fsec * 1000) / 1000;
3594+
fsec = floor(fsec * 1000) / 1000;
35953595
#endif
35963596
break;
35973597
case DTK_MICROSEC:
35983598
#ifndef HAVE_INT64_TIMESTAMP
3599-
fsec = rint(fsec * 1000000) / 1000000;
3599+
fsec = floor(fsec * 1000000) / 1000000;
36003600
#endif
36013601
break;
36023602

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy