Skip to content

Commit 09ff9db

Browse files
committed
Remove more extraneous parentheses in date/time functions.
1 parent a99b285 commit 09ff9db

File tree

9 files changed

+391
-414
lines changed

9 files changed

+391
-414
lines changed

src/backend/utils/adt/date.c

Lines changed: 53 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/adt/date.c,v 1.107 2005/05/23 21:54:01 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/date.c,v 1.108 2005/05/24 02:09:45 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -921,10 +921,10 @@ static int
921921
tm2time(struct pg_tm * tm, fsec_t fsec, TimeADT *result)
922922
{
923923
#ifdef HAVE_INT64_TIMESTAMP
924-
*result = ((((((tm->tm_hour * 60) + tm->tm_min) * 60) + tm->tm_sec)
925-
* USECS_PER_SEC) + fsec);
924+
*result = ((((tm->tm_hour * 60 + tm->tm_min) * 60) + tm->tm_sec)
925+
* USECS_PER_SEC) + fsec;
926926
#else
927-
*result = ((((tm->tm_hour * 60) + tm->tm_min) * 60) + tm->tm_sec + fsec);
927+
*result = ((tm->tm_hour * 60 + tm->tm_min) * 60) + tm->tm_sec + fsec;
928928
#endif
929929
return 0;
930930
}
@@ -938,12 +938,12 @@ static int
938938
time2tm(TimeADT time, struct pg_tm * tm, fsec_t *fsec)
939939
{
940940
#ifdef HAVE_INT64_TIMESTAMP
941-
tm->tm_hour = (time / USECS_PER_HOUR);
942-
time -= (tm->tm_hour * USECS_PER_HOUR);
943-
tm->tm_min = (time / USECS_PER_MINUTE);
944-
time -= (tm->tm_min * USECS_PER_MINUTE);
945-
tm->tm_sec = (time / USECS_PER_SEC);
946-
time -= (tm->tm_sec * USECS_PER_SEC);
941+
tm->tm_hour = time / USECS_PER_HOUR;
942+
time -= tm->tm_hour * USECS_PER_HOUR;
943+
tm->tm_min = time / USECS_PER_MINUTE;
944+
time -= tm->tm_min * USECS_PER_MINUTE;
945+
tm->tm_sec = time / USECS_PER_SEC;
946+
time -= tm->tm_sec * USECS_PER_SEC;
947947
*fsec = time;
948948
#else
949949
double trem;
@@ -1077,7 +1077,7 @@ AdjustTimeForTypmod(TimeADT *time, int32 typmod)
10771077
};
10781078
#endif
10791079

1080-
if ((typmod >= 0) && (typmod <= MAX_TIME_PRECISION))
1080+
if (typmod >= 0 && typmod <= MAX_TIME_PRECISION)
10811081
{
10821082
/*
10831083
* Note: this round-to-nearest code is not completely consistent
@@ -1089,17 +1089,17 @@ AdjustTimeForTypmod(TimeADT *time, int32 typmod)
10891089
#ifdef HAVE_INT64_TIMESTAMP
10901090
if (*time >= INT64CONST(0))
10911091
{
1092-
*time = (((*time + TimeOffsets[typmod]) / TimeScales[typmod])
1093-
* TimeScales[typmod]);
1092+
*time = ((*time + TimeOffsets[typmod]) / TimeScales[typmod]) *
1093+
TimeScales[typmod];
10941094
}
10951095
else
10961096
{
1097-
*time = -((((-*time) + TimeOffsets[typmod]) / TimeScales[typmod])
1098-
* TimeScales[typmod]);
1097+
*time = -((((-*time) + TimeOffsets[typmod]) / TimeScales[typmod]) *
1098+
TimeScales[typmod]);
10991099
}
11001100
#else
1101-
*time = (rint(((double) *time) * TimeScales[typmod])
1102-
/ TimeScales[typmod]);
1101+
*time = rint((double)*time * TimeScales[typmod])
1102+
/ TimeScales[typmod];
11031103
#endif
11041104
}
11051105
}
@@ -1342,10 +1342,10 @@ timestamp_time(PG_FUNCTION_ARGS)
13421342
* Could also do this with time = (timestamp / USECS_PER_DAY *
13431343
* USECS_PER_DAY) - timestamp;
13441344
*/
1345-
result = ((((((tm->tm_hour * 60) + tm->tm_min) * 60) + tm->tm_sec)
1346-
* USECS_PER_SEC) + fsec);
1345+
result = ((((tm->tm_hour * 60 + tm->tm_min) * 60) + tm->tm_sec) *
1346+
USECS_PER_SEC) + fsec;
13471347
#else
1348-
result = ((((tm->tm_hour * 60) + tm->tm_min) * 60) + tm->tm_sec + fsec);
1348+
result = ((tm->tm_hour * 60 + tm->tm_min) * 60) + tm->tm_sec + fsec;
13491349
#endif
13501350

13511351
PG_RETURN_TIMEADT(result);
@@ -1379,10 +1379,10 @@ timestamptz_time(PG_FUNCTION_ARGS)
13791379
* Could also do this with time = (timestamp / USECS_PER_DAY *
13801380
* USECS_PER_DAY) - timestamp;
13811381
*/
1382-
result = ((((((tm->tm_hour * 60) + tm->tm_min) * 60) + tm->tm_sec)
1383-
* USECS_PER_SEC) + fsec);
1382+
result = ((((tm->tm_hour * 60 + tm->tm_min) * 60) + tm->tm_sec) *
1383+
USECS_PER_SEC) + fsec;
13841384
#else
1385-
result = ((((tm->tm_hour * 60) + tm->tm_min) * 60) + tm->tm_sec + fsec);
1385+
result = ((tm->tm_hour * 60 + tm->tm_min) * 60) + tm->tm_sec + fsec;
13861386
#endif
13871387

13881388
PG_RETURN_TIMEADT(result);
@@ -1624,26 +1624,25 @@ time_part(PG_FUNCTION_ARGS)
16241624
{
16251625
case DTK_MICROSEC:
16261626
#ifdef HAVE_INT64_TIMESTAMP
1627-
result = ((tm->tm_sec * USECS_PER_SEC) + fsec);
1627+
result = tm->tm_sec * USECS_PER_SEC + fsec;
16281628
#else
1629-
result = ((tm->tm_sec + fsec) * 1000000);
1629+
result = (tm->tm_sec + fsec) * 1000000;
16301630
#endif
16311631
break;
16321632

16331633
case DTK_MILLISEC:
16341634
#ifdef HAVE_INT64_TIMESTAMP
1635-
result = ((tm->tm_sec * INT64CONST(1000))
1636-
+ (fsec / INT64CONST(1000)));
1635+
result = tm->tm_sec * INT64CONST(1000) + fsec / INT64CONST(1000);
16371636
#else
1638-
result = ((tm->tm_sec + fsec) * 1000);
1637+
result = (tm->tm_sec + fsec) * 1000;
16391638
#endif
16401639
break;
16411640

16421641
case DTK_SECOND:
16431642
#ifdef HAVE_INT64_TIMESTAMP
1644-
result = (tm->tm_sec + (fsec / USECS_PER_SEC));
1643+
result = tm->tm_sec + fsec / USECS_PER_SEC;
16451644
#else
1646-
result = (tm->tm_sec + fsec);
1645+
result = tm->tm_sec + fsec;
16471646
#endif
16481647
break;
16491648

@@ -1675,7 +1674,7 @@ time_part(PG_FUNCTION_ARGS)
16751674
result = 0;
16761675
}
16771676
}
1678-
else if ((type == RESERV) && (val == DTK_EPOCH))
1677+
else if (type == RESERV && val == DTK_EPOCH)
16791678
{
16801679
#ifdef HAVE_INT64_TIMESTAMP
16811680
result = (time / 1000000e0);
@@ -1708,10 +1707,10 @@ static int
17081707
tm2timetz(struct pg_tm * tm, fsec_t fsec, int tz, TimeTzADT *result)
17091708
{
17101709
#ifdef HAVE_INT64_TIMESTAMP
1711-
result->time = ((((((tm->tm_hour * 60) + tm->tm_min) * 60) + tm->tm_sec)
1712-
* USECS_PER_SEC) + fsec);
1710+
result->time = ((((tm->tm_hour * 60 + tm->tm_min) * 60) + tm->tm_sec) *
1711+
USECS_PER_SEC) + fsec;
17131712
#else
1714-
result->time = ((((tm->tm_hour * 60) + tm->tm_min) * 60) + tm->tm_sec + fsec);
1713+
result->time = ((tm->tm_hour * 60 + tm->tm_min) * 60) + tm->tm_sec + fsec;
17151714
#endif
17161715
result->zone = tz;
17171716

@@ -1823,12 +1822,12 @@ timetz2tm(TimeTzADT *time, struct pg_tm * tm, fsec_t *fsec, int *tzp)
18231822
#ifdef HAVE_INT64_TIMESTAMP
18241823
int64 trem = time->time;
18251824

1826-
tm->tm_hour = (trem / USECS_PER_HOUR);
1827-
trem -= (tm->tm_hour * USECS_PER_HOUR);
1828-
tm->tm_min = (trem / USECS_PER_MINUTE);
1829-
trem -= (tm->tm_min * USECS_PER_MINUTE);
1830-
tm->tm_sec = (trem / USECS_PER_SEC);
1831-
*fsec = (trem - (tm->tm_sec * USECS_PER_SEC));
1825+
tm->tm_hour = trem / USECS_PER_HOUR;
1826+
trem -= tm->tm_hour * USECS_PER_HOUR;
1827+
tm->tm_min = trem / USECS_PER_MINUTE;
1828+
trem -= tm->tm_min * USECS_PER_MINUTE;
1829+
tm->tm_sec = trem / USECS_PER_SEC;
1830+
*fsec = trem - tm->tm_sec * USECS_PER_SEC;
18321831
#else
18331832
double trem = time->time;
18341833

@@ -2281,10 +2280,9 @@ datetimetz_timestamptz(PG_FUNCTION_ARGS)
22812280
TimestampTz result;
22822281

22832282
#ifdef HAVE_INT64_TIMESTAMP
2284-
result = (((date *USECS_PER_DAY) +time->time)
2285-
+ (time->zone * USECS_PER_SEC));
2283+
result = (date * USECS_PER_DAY + time->time) + time->zone * USECS_PER_SEC;
22862284
#else
2287-
result = (((date *(double)SECS_PER_DAY) +time->time) + time->zone);
2285+
result = date * (double)SECS_PER_DAY + time->time + time->zone;
22882286
#endif
22892287

22902288
PG_RETURN_TIMESTAMP(result);
@@ -2400,26 +2398,25 @@ timetz_part(PG_FUNCTION_ARGS)
24002398

24012399
case DTK_MICROSEC:
24022400
#ifdef HAVE_INT64_TIMESTAMP
2403-
result = ((tm->tm_sec * USECS_PER_SEC) + fsec);
2401+
result = tm->tm_sec * USECS_PER_SEC + fsec;
24042402
#else
2405-
result = ((tm->tm_sec + fsec) * 1000000);
2403+
result = (tm->tm_sec + fsec) * 1000000;
24062404
#endif
24072405
break;
24082406

24092407
case DTK_MILLISEC:
24102408
#ifdef HAVE_INT64_TIMESTAMP
2411-
result = ((tm->tm_sec * INT64CONST(1000))
2412-
+ (fsec / INT64CONST(1000)));
2409+
result = tm->tm_sec * INT64CONST(1000) + fsec / INT64CONST(1000);
24132410
#else
2414-
result = ((tm->tm_sec + fsec) * 1000);
2411+
result = (tm->tm_sec + fsec) * 1000;
24152412
#endif
24162413
break;
24172414

24182415
case DTK_SECOND:
24192416
#ifdef HAVE_INT64_TIMESTAMP
2420-
result = (tm->tm_sec + (fsec / USECS_PER_SEC));
2417+
result = tm->tm_sec + fsec / USECS_PER_SEC;
24212418
#else
2422-
result = (tm->tm_sec + fsec);
2419+
result = tm->tm_sec + fsec;
24232420
#endif
24242421
break;
24252422

@@ -2448,12 +2445,12 @@ timetz_part(PG_FUNCTION_ARGS)
24482445
result = 0;
24492446
}
24502447
}
2451-
else if ((type == RESERV) && (val == DTK_EPOCH))
2448+
else if (type == RESERV && val == DTK_EPOCH)
24522449
{
24532450
#ifdef HAVE_INT64_TIMESTAMP
2454-
result = ((time->time / 1000000e0) + time->zone);
2451+
result = time->time / 1000000e0 + time->zone;
24552452
#else
2456-
result = (time->time + time->zone);
2453+
result = time->time + time->zone;
24572454
#endif
24582455
}
24592456
else
@@ -2492,11 +2489,11 @@ timetz_zone(PG_FUNCTION_ARGS)
24922489

24932490
result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
24942491

2495-
if ((type == TZ) || (type == DTZ))
2492+
if (type == TZ || type == DTZ)
24962493
{
24972494
tz = val * 60;
24982495
#ifdef HAVE_INT64_TIMESTAMP
2499-
result->time = time->time + ((time->zone - tz) * USECS_PER_SEC);
2496+
result->time = time->time + (time->zone - tz) * USECS_PER_SEC;
25002497
while (result->time < INT64CONST(0))
25012498
result->time += USECS_PER_DAY;
25022499
while (result->time >= USECS_PER_DAY)
@@ -2550,7 +2547,7 @@ timetz_izone(PG_FUNCTION_ARGS)
25502547
result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
25512548

25522549
#ifdef HAVE_INT64_TIMESTAMP
2553-
result->time = time->time + ((time->zone - tz) * USECS_PER_SEC);
2550+
result->time = time->time + (time->zone - tz) * USECS_PER_SEC;
25542551
while (result->time < INT64CONST(0))
25552552
result->time += USECS_PER_DAY;
25562553
while (result->time >= USECS_PER_DAY)

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