Fix internal extract(timezone_minute) formulas
authorPeter Eisentraut <peter@eisentraut.org>
Thu, 1 Apr 2021 14:12:53 +0000 (16:12 +0200)
committerPeter Eisentraut <peter@eisentraut.org>
Thu, 1 Apr 2021 14:12:53 +0000 (16:12 +0200)
Through various refactorings over time, the extract(timezone_minute
from time with time zone) and extract(timezone_minute from timestamp
with time zone) implementations ended up with two different but
equally nonsensical formulas by using SECS_PER_MINUTE and
MINS_PER_HOUR interchangeably.  Since those two are of course both the
same number, the formulas do work, but for readability, fix them to be
semantically correct.

src/backend/utils/adt/date.c
src/backend/utils/adt/timestamp.c

index 68d99a5099206c8e92ac8e07f55e989018708a99..6053d0e8a6f344ef83f8128b79551701927a7a4e 100644 (file)
@@ -2726,7 +2726,7 @@ timetz_part(PG_FUNCTION_ARGS)
            case DTK_TZ_MINUTE:
                result = -tz;
                result /= SECS_PER_MINUTE;
-               FMODULO(result, dummy, (double) SECS_PER_MINUTE);
+               FMODULO(result, dummy, (double) MINS_PER_HOUR);
                break;
 
            case DTK_TZ_HOUR:
index f619b56d6f5465bfa457b7ec1dc7afd98542c307..194861f19e3a072cf6f472720eeeb9c45aad989c 100644 (file)
@@ -4844,7 +4844,7 @@ timestamptz_part(PG_FUNCTION_ARGS)
 
            case DTK_TZ_MINUTE:
                result = -tz;
-               result /= MINS_PER_HOUR;
+               result /= SECS_PER_MINUTE;
                FMODULO(result, dummy, (double) MINS_PER_HOUR);
                break;