Thread: Remove unnecessary parentheses

Remove unnecessary parentheses

From
Bruce Momjian
Date:
I found many unnecessary parentheses in the datetime/timestamp code.

This applied patch removes them.

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073
Index: datetime.c
===================================================================
RCS file: /cvsroot/pgsql/src/backend/utils/adt/datetime.c,v
retrieving revision 1.140
diff -r1.140 datetime.c
687c687
<     if (strcmp((str + len - 4), "0001") == 0)
---
>     if (strcmp(str + len - 4, "0001") == 0)
695,696c695
<     while ((*(str + len - 1) == '0')
<            && (*(str + len - 3) != '.'))
---
>     while (*(str + len - 1) == '0' && *(str + len - 3) != '.')
772c771
<             else if ((*cp == '-') || (*cp == '/') || (*cp == '.'))
---
>             else if (*cp == '-' || *cp == '/' || *cp == '.')
793c792
<                         while (isdigit((unsigned char) *cp) || (*cp == delim))
---
>                         while (isdigit((unsigned char) *cp) || *cp == delim)
800c799
<                     while (isalnum((unsigned char) *cp) || (*cp == delim))
---
>                     while (isalnum((unsigned char) *cp) || *cp == delim)
837c836
<             if ((*cp == '-') || (*cp == '/') || (*cp == '.'))
---
>             if (*cp == '-' || *cp == '/' || *cp == '.')
843c842
<                 while (isdigit((unsigned char) *cp) || (*cp == delim))
---
>                 while (isdigit((unsigned char) *cp) || *cp == delim)
848c847
<         else if ((*cp == '+') || (*cp == '-'))
---
>         else if (*cp == '+' || *cp == '-')
860c859
<                        (*cp == ':') || (*cp == '.'))
---
>                        *cp == ':' || *cp == '.')
985,986c984
<                 else if (((fmask & DTK_DATE_M) == DTK_DATE_M)
<                          || (ptype != 0))
---
>                 else if ((fmask & DTK_DATE_M) == DTK_DATE_M || ptype != 0)
1086,1088c1084,1086
<                     if ((i > 0) && ((fmask & DTK_M(TZ)) != 0)
<                         && (ftype[i - 1] == DTK_TZ)
<                         && (isalpha((unsigned char) *field[i - 1])))
---
>                     if (i > 0 && (fmask & DTK_M(TZ)) != 0 &&
>                         ftype[i - 1] == DTK_TZ &&
>                         isalpha((unsigned char) *field[i - 1]))
1145,1146c1143,1144
<                             if (((fmask & DTK_M(MONTH)) != 0)
<                                 && ((fmask & DTK_M(HOUR)) != 0))
---
>                             if ((fmask & DTK_M(MONTH)) != 0 &&
>                                 (fmask & DTK_M(HOUR)) != 0)
1215,1216c1213,1215
<                                 dt2time((time * INT64CONST(86400000000)),
<                                         &tm->tm_hour, &tm->tm_min, &tm->tm_sec, fsec);
---
>                                 dt2time(time * INT64CONST(86400000000),
>                                         &tm->tm_hour, &tm->tm_min,
>                                         &tm->tm_sec, fsec);
1218,1219c1217,1218
<                                 dt2time((time * 86400),
<                                         &tm->tm_hour, &tm->tm_min, &tm->tm_sec, fsec);
---
>                                 dt2time(time * 86400, &tm->tm_hour,
>                                         &tm->tm_min, &tm->tm_sec, fsec);
1255c1254
<                     if ((cp != NULL) && !(fmask & DTK_DATE_M))
---
>                     if (cp != NULL && !(fmask & DTK_DATE_M))
1262c1261
<                     else if ((cp != NULL) && ((flen - strlen(cp)) > 2))
---
>                     else if (cp != NULL && flen - strlen(cp) > 2)
1328,1329c1327,1328
<                                 j2date((date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) - 1),
<                                 &tm->tm_year, &tm->tm_mon, &tm->tm_mday);
---
>                                 j2date(date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) - 1,
>                                         &tm->tm_year, &tm->tm_mon, &tm->tm_mday);
1348,1349c1347,1348
<                                 j2date((date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) + 1),
<                                 &tm->tm_year, &tm->tm_mon, &tm->tm_mday);
---
>                                 j2date(date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) + 1,
>                                         &tm->tm_year, &tm->tm_mon, &tm->tm_mday);
1377,1379c1376,1378
<                         if ((fmask & DTK_M(MONTH)) && (!haveTextMonth)
<                             && (!(fmask & DTK_M(DAY)))
<                             && ((tm->tm_mon >= 1) && (tm->tm_mon <= 31)))
---
>                         if ((fmask & DTK_M(MONTH)) && !haveTextMonth &&
>                             !(fmask & DTK_M(DAY)) && tm->tm_mon >= 1 &&
>                             tm->tm_mon <= 31)
1462,1465c1461,1464
<                         if ((i >= (nf - 1))
<                             || ((ftype[i + 1] != DTK_NUMBER)
<                                 && (ftype[i + 1] != DTK_TIME)
<                                 && (ftype[i + 1] != DTK_DATE)))
---
>                         if (i >= nf - 1 ||
>                             (ftype[i + 1] != DTK_NUMBER &&
>                              ftype[i + 1] != DTK_TIME &&
>                              ftype[i + 1] != DTK_DATE))
1528c1527
<     if ((mer != HR24) && (tm->tm_hour > 12))
---
>     if (mer != HR24 && tm->tm_hour > 12)
1530c1529
<     if ((mer == AM) && (tm->tm_hour == 12))
---
>     if (mer == AM && tm->tm_hour == 12)
1532c1531
<     else if ((mer == PM) && (tm->tm_hour != 12))
---
>     else if (mer == PM && tm->tm_hour != 12)
1653,1654c1652,1655
<     if ((before_gmtoff > 0) ? (mytime < 0 && beforetime > 0) :
<         (mytime > 0 && beforetime < 0))
---
>     if ((before_gmtoff > 0 &&
>          mytime < 0 && beforetime > 0) ||
>         (before_gmtoff <= 0 &&
>          mytime > 0 && beforetime < 0))
1657,1658c1658,1661
<     if ((after_gmtoff > 0) ? (mytime < 0 && aftertime > 0) :
<         (mytime > 0 && aftertime < 0))
---
>     if ((after_gmtoff > 0 &&
>          mytime < 0 && aftertime > 0) ||
>         (after_gmtoff <= 0 &&
>          mytime > 0 && aftertime < 0))
1744,1746c1747,1748
<                 if ((i == 0) && (nf >= 2)
<                     && ((ftype[nf - 1] == DTK_DATE)
<                         || (ftype[1] == DTK_TIME)))
---
>                 if (i == 0 && nf >= 2 &&
>                     (ftype[nf - 1] == DTK_DATE || ftype[1] == DTK_TIME))
1829,1830c1831,1833
<                     if ((i > 0) && ((fmask & DTK_M(TZ)) != 0)
<                         && (ftype[i - 1] == DTK_TZ) && (isalpha((unsigned char) *field[i - 1])))
---
>                     if (i > 0 && (fmask & DTK_M(TZ)) != 0 &&
>                         ftype[i - 1] == DTK_TZ &&
>                         isalpha((unsigned char) *field[i - 1]))
1900,1901c1903,1904
<                             if (((fmask & DTK_M(MONTH)) != 0)
<                                 && ((fmask & DTK_M(HOUR)) != 0))
---
>                             if ((fmask & DTK_M(MONTH)) != 0 &&
>                                 (fmask & DTK_M(HOUR)) != 0)
1969c1972
<                                 dt2time((time * INT64CONST(86400000000)),
---
>                                 dt2time(time * INT64CONST(86400000000),
1972c1975
<                                 dt2time((time * 86400),
---
>                                 dt2time(time * 86400,
2015c2018
<                         if ((i == 0) && ((nf >= 2) && (ftype[nf - 1] == DTK_DATE)))
---
>                         if (i == 0 && nf >= 2 && ftype[nf - 1] == DTK_DATE)
2022c2025
<                         else if ((flen - strlen(cp)) > 2)
---
>                         else if (flen - strlen(cp) > 2)
2160,2163c2163,2166
<                         if ((i >= (nf - 1))
<                             || ((ftype[i + 1] != DTK_NUMBER)
<                                 && (ftype[i + 1] != DTK_TIME)
<                                 && (ftype[i + 1] != DTK_DATE)))
---
>                         if (i >= nf - 1 ||
>                             (ftype[i + 1] != DTK_NUMBER &&
>                              ftype[i + 1] != DTK_TIME &&
>                              ftype[i + 1] != DTK_DATE))
2183c2186
<     if ((mer != HR24) && (tm->tm_hour > 12))
---
>     if (mer != HR24 && tm->tm_hour > 12)
2185c2188
<     if ((mer == AM) && (tm->tm_hour == 12))
---
>     if (mer == AM && tm->tm_hour == 12)
2187c2190
<     else if ((mer == PM) && (tm->tm_hour != 12))
---
>     else if (mer == PM && tm->tm_hour != 12)
2191,2194c2194,2196
<     if ((tm->tm_hour < 0) || (tm->tm_hour > 23)
<         || (tm->tm_min < 0) || (tm->tm_min > 59)
<         || (tm->tm_sec < 0) || (tm->tm_sec > 60)
<         || (*fsec < INT64CONST(0)) || (*fsec >= INT64CONST(1000000)))
---
>     if (tm->tm_hour < 0 || tm->tm_hour > 23 || tm->tm_min < 0 ||
>         tm->tm_min > 59 || tm->tm_sec < 0 || tm->tm_sec > 60 ||
>         *fsec < INT64CONST(0) || *fsec >= INT64CONST(1000000))
2197,2200c2199,2201
<     if ((tm->tm_hour < 0) || (tm->tm_hour > 23)
<         || (tm->tm_min < 0) || (tm->tm_min > 59)
<         || (tm->tm_sec < 0) || (tm->tm_sec > 60)
<         || (*fsec < 0) || (*fsec >= 1))
---
>     if (tm->tm_hour < 0 || tm->tm_hour > 23 || tm->tm_min < 0 ||
>         tm->tm_min > 59 || tm->tm_sec < 0 || tm->tm_sec > 60 ||
>         *fsec < 0 || *fsec >= 1)
2261c2262
<     while ((*str != '\0') && (nf < MAXDATEFIELDS))
---
>     while (*str != '\0' && nf < MAXDATEFIELDS)
2447,2450c2448,2450
<     if ((tm->tm_hour < 0)
<         || (tm->tm_min < 0) || (tm->tm_min > 59)
<         || (tm->tm_sec < 0) || (tm->tm_sec > 60)
<         || (*fsec < INT64CONST(0)) || (*fsec >= INT64CONST(1000000)))
---
>     if (tm->tm_hour < 0 || tm->tm_min < 0 || tm->tm_min > 59 ||
>         tm->tm_sec < 0 || tm->tm_sec > 60 || *fsec < INT64CONST(0) ||
>         *fsec >= INT64CONST(1000000))
2453,2456c2453,2454
<     if ((tm->tm_hour < 0)
<         || (tm->tm_min < 0) || (tm->tm_min > 59)
<         || (tm->tm_sec < 0) || (tm->tm_sec > 60)
<         || (*fsec < 0) || (*fsec >= 1))
---
>     if (tm->tm_hour < 0 || tm->tm_min < 0 || tm->tm_min > 59 ||
>         tm->tm_sec < 0 || tm->tm_sec > 60 || *fsec < 0 || *fsec >= 1)
2490c2488
<         if ((cp - str) > 2)
---
>         if (cp - str > 2)
2514,2516c2512,2513
<     if ((flen == 3) &&
<         ((fmask & DTK_DATE_M) == DTK_M(YEAR)) &&
<         ((val >= 1) && (val <= 366)))
---
>     if (flen == 3 && (fmask & DTK_DATE_M) == DTK_M(YEAR) && val >= 1 &&
>         val <= 366)
2767c2764
<     hr = strtol((str + 1), &cp, 10);
---
>     hr = strtol(str + 1, &cp, 10);
2771c2768
<         min = strtol((cp + 1), &cp, 10);
---
>         min = strtol(cp + 1, &cp, 10);
2773c2770
<     else if ((*cp == '\0') && (strlen(str) > 3))
---
>     else if (*cp == '\0' && strlen(str) > 3)
2781c2778
<     if ((hr < 0) || (hr > 13))
---
>     if (hr < 0 || hr > 13)
2783c2780
<     if ((min < 0) || (min >= 60))
---
>     if (min < 0 || min >= 60)
2869,2870c2866,2867
<     if ((datecache[field] != NULL)
<         && (strncmp(lowtoken, datecache[field]->token, TOKMAXLEN) == 0))
---
>     if (datecache[field] != NULL &&
>         strncmp(lowtoken, datecache[field]->token, TOKMAXLEN) == 0)
2960c2957
<                 Assert((*field[i] == '-') || (*field[i] == '+'));
---
>                 Assert(*field[i] == '-' || *field[i] == '+');
2968c2965
<                 while ((*cp != '\0') && (*cp != ':') && (*cp != '.'))
---
>                 while (*cp != '\0' && *cp != ':' && *cp != '.')
2970,2971c2967,2968
<                 if ((*cp == ':') &&
<                 (DecodeTime(field[i] + 1, fmask, &tmask, tm, fsec) == 0))
---
>                 if (*cp == ':' &&
>                     DecodeTime(field[i] + 1, fmask, &tmask, tm, fsec) == 0)
3114c3111
<                         tmask = ((fmask & DTK_M(DAY)) ? 0 : DTK_M(DAY));
---
>                         tmask = (fmask & DTK_M(DAY)) ? 0 : DTK_M(DAY);
3132c3129
<                         tmask = ((fmask & DTK_M(DAY)) ? 0 : DTK_M(DAY));
---
>                         tmask = (fmask & DTK_M(DAY)) ? 0 : DTK_M(DAY);
3157c3154
<                         tmask = ((fmask & DTK_M(YEAR)) ? 0 : DTK_M(YEAR));
---
>                         tmask = (fmask & DTK_M(YEAR)) ? 0 : DTK_M(YEAR);
3164c3161
<                         tmask = ((fmask & DTK_M(YEAR)) ? 0 : DTK_M(YEAR));
---
>                         tmask = (fmask & DTK_M(YEAR)) ? 0 : DTK_M(YEAR);
3171c3168
<                         tmask = ((fmask & DTK_M(YEAR)) ? 0 : DTK_M(YEAR));
---
>                         tmask = (fmask & DTK_M(YEAR)) ? 0 : DTK_M(YEAR);
3178c3175
<                         tmask = ((fmask & DTK_M(YEAR)) ? 0 : DTK_M(YEAR));
---
>                         tmask = (fmask & DTK_M(YEAR)) ? 0 : DTK_M(YEAR);
3265,3266c3262,3263
<     if ((deltacache[field] != NULL)
<         && (strncmp(lowtoken, deltacache[field]->token, TOKMAXLEN) == 0))
---
>     if (deltacache[field] != NULL &&
>         strncmp(lowtoken, deltacache[field]->token, TOKMAXLEN) == 0)
3279c3276
<         if ((type == TZ) || (type == DTZ))
---
>         if (type == TZ || type == DTZ)
3375c3372
<     if ((tm->tm_mon < 1) || (tm->tm_mon > 12))
---
>     if (tm->tm_mon < 1 || tm->tm_mon > 12)
3397c3394
<                 sprintf((str + 5), "/%04d", tm->tm_year);
---
>                 sprintf(str + 5, "/%04d", tm->tm_year);
3399c3396
<                 sprintf((str + 5), "/%04d %s", -(tm->tm_year - 1), "BC");
---
>                 sprintf(str + 5, "/%04d %s", -(tm->tm_year - 1), "BC");
3406c3403
<                 sprintf((str + 5), ".%04d", tm->tm_year);
---
>                 sprintf(str + 5, ".%04d", tm->tm_year);
3408c3405
<                 sprintf((str + 5), ".%04d %s", -(tm->tm_year - 1), "BC");
---
>                 sprintf(str + 5, ".%04d %s", -(tm->tm_year - 1), "BC");
3419c3416
<                 sprintf((str + 5), "-%04d", tm->tm_year);
---
>                 sprintf(str + 5, "-%04d", tm->tm_year);
3421c3418
<                 sprintf((str + 5), "-%04d %s", -(tm->tm_year - 1), "BC");
---
>                 sprintf(str + 5, "-%04d %s", -(tm->tm_year - 1), "BC");
3435c3432
<     if ((tm->tm_hour < 0) || (tm->tm_hour > 24))
---
>     if (tm->tm_hour < 0 || tm->tm_hour > 24)
3448c3445
<         sprintf((str + strlen(str)), ":%02d.%06d", tm->tm_sec, fsec);
---
>         sprintf(str + strlen(str), ":%02d.%06d", tm->tm_sec, fsec);
3450c3447
<         sprintf((str + strlen(str)), ":%013.10f", tm->tm_sec + fsec);
---
>         sprintf(str + strlen(str), ":%013.10f", tm->tm_sec + fsec);
3453,3454c3450,3451
<         while ((strcmp((str + strlen(str) - 2), "00") == 0)
<                && (*(str + strlen(str) - 3) != '.'))
---
>         while (strcmp((str + strlen(str) - 2), "00") == 0 &&
>             *(str + strlen(str) - 3) != '.')
3458c3455
<         sprintf((str + strlen(str)), ":%02d", tm->tm_sec);
---
>         sprintf(str + strlen(str), ":%02d", tm->tm_sec);
3466,3467c3463,3464
<         min = ((abs(*tzp) / 60) % 60);
<         sprintf((str + strlen(str)), ((min != 0) ? "%+03d:%02d" : "%+03d"), hour, min);
---
>         min = (abs(*tzp) / 60) % 60;
>         sprintf(str + strlen(str), (min != 0) ? "%+03d:%02d" : "%+03d", hour, min);
3494c3491
<      * assert... if ((tm->tm_mon < 1) || (tm->tm_mon > 12)) return -1;
---
>      * assert... if (tm->tm_mon < 1 || tm->tm_mon > 12) return -1;
3496c3493
<     Assert((tm->tm_mon >= 1) && (tm->tm_mon <= 12));
---
>     Assert(tm->tm_mon >= 1 && tm->tm_mon <= 12);
3504c3501
<                   ((tm->tm_year > 0) ? tm->tm_year : -(tm->tm_year - 1)),
---
>                     (tm->tm_year > 0) ? tm->tm_year : -(tm->tm_year - 1),
3517c3514
<                 sprintf((str + strlen(str)), ":%02d.%06d", tm->tm_sec, fsec);
---
>                 sprintf(str + strlen(str), ":%02d.%06d", tm->tm_sec, fsec);
3521c3518
<             if ((fsec != 0) && (tm->tm_year > 0))
---
>             if (fsec != 0 && tm->tm_year > 0)
3523c3520
<                 sprintf((str + strlen(str)), ":%09.6f", tm->tm_sec + fsec);
---
>                 sprintf(str + strlen(str), ":%09.6f", tm->tm_sec + fsec);
3528c3525
<                 sprintf((str + strlen(str)), ":%02d", tm->tm_sec);
---
>                 sprintf(str + strlen(str), ":%02d", tm->tm_sec);
3539,3540c3536,3537
<                 min = ((abs(*tzp) / 60) % 60);
<                 sprintf((str + strlen(str)), ((min != 0) ? "%+03d:%02d" : "%+03d"), hour, min);
---
>                 min = (abs(*tzp) / 60) % 60;
>                 sprintf(str + strlen(str), (min != 0) ? "%+03d:%02d" : "%+03d", hour, min);
3544c3541
<                 sprintf((str + strlen(str)), " BC");
---
>                 sprintf(str + strlen(str), " BC");
3555,3556c3552,3553
<             sprintf((str + 5), "/%04d %02d:%02d",
<                   ((tm->tm_year > 0) ? tm->tm_year : -(tm->tm_year - 1)),
---
>             sprintf(str + 5, "/%04d %02d:%02d",
>                     (tm->tm_year > 0) ? tm->tm_year : -(tm->tm_year - 1),
3569c3566
<                 sprintf((str + strlen(str)), ":%02d.%06d", tm->tm_sec, fsec);
---
>                 sprintf(str + strlen(str), ":%02d.%06d", tm->tm_sec, fsec);
3573c3570
<             if ((fsec != 0) && (tm->tm_year > 0))
---
>             if (fsec != 0 && tm->tm_year > 0)
3575c3572
<                 sprintf((str + strlen(str)), ":%09.6f", tm->tm_sec + fsec);
---
>                 sprintf(str + strlen(str), ":%09.6f", tm->tm_sec + fsec);
3580c3577
<                 sprintf((str + strlen(str)), ":%02d", tm->tm_sec);
---
>                 sprintf(str + strlen(str), ":%02d", tm->tm_sec);
3585c3582
<                     sprintf((str + strlen(str)), " %.*s", MAXTZLEN, *tzn);
---
>                     sprintf(str + strlen(str), " %.*s", MAXTZLEN, *tzn);
3589,3590c3586,3587
<                     min = ((abs(*tzp) / 60) % 60);
<                     sprintf((str + strlen(str)), ((min != 0) ? "%+03d:%02d" : "%+03d"), hour, min);
---
>                     min = (abs(*tzp) / 60) % 60;
>                     sprintf(str + strlen(str), (min != 0) ? "%+03d:%02d" : "%+03d", hour, min);
3595c3592
<                 sprintf((str + strlen(str)), " BC");
---
>                 sprintf(str + strlen(str), " BC");
3603,3604c3600,3601
<             sprintf((str + 5), ".%04d %02d:%02d",
<                   ((tm->tm_year > 0) ? tm->tm_year : -(tm->tm_year - 1)),
---
>             sprintf(str + 5, ".%04d %02d:%02d",
>                     (tm->tm_year > 0) ? tm->tm_year : -(tm->tm_year - 1),
3617c3614
<                 sprintf((str + strlen(str)), ":%02d.%06d", tm->tm_sec, fsec);
---
>                 sprintf(str + strlen(str), ":%02d.%06d", tm->tm_sec, fsec);
3621c3618
<             if ((fsec != 0) && (tm->tm_year > 0))
---
>             if (fsec != 0 && tm->tm_year > 0)
3623c3620
<                 sprintf((str + strlen(str)), ":%09.6f", tm->tm_sec + fsec);
---
>                 sprintf(str + strlen(str), ":%09.6f", tm->tm_sec + fsec);
3628c3625
<                 sprintf((str + strlen(str)), ":%02d", tm->tm_sec);
---
>                 sprintf(str + strlen(str), ":%02d", tm->tm_sec);
3633c3630
<                     sprintf((str + strlen(str)), " %.*s", MAXTZLEN, *tzn);
---
>                     sprintf(str + strlen(str), " %.*s", MAXTZLEN, *tzn);
3637,3638c3634,3635
<                     min = ((abs(*tzp) / 60) % 60);
<                     sprintf((str + strlen(str)), ((min != 0) ? "%+03d:%02d" : "%+03d"), hour, min);
---
>                     min = (abs(*tzp) / 60) % 60;
>                     sprintf(str + strlen(str), (min != 0) ? "%+03d:%02d" : "%+03d", hour, min);
3643c3640
<                 sprintf((str + strlen(str)), " BC");
---
>                 sprintf(str + strlen(str), " BC");
3654,3655c3651,3652
<             strcpy((str + 3), " ");
<
---
>             strcpy(str + 3, " ");
>
3657c3654
<                 sprintf((str + 4), "%02d %3s", tm->tm_mday, months[tm->tm_mon - 1]);
---
>                 sprintf(str + 4, "%02d %3s", tm->tm_mday, months[tm->tm_mon - 1]);
3659c3656
<                 sprintf((str + 4), "%3s %02d", months[tm->tm_mon - 1], tm->tm_mday);
---
>                 sprintf(str + 4, "%3s %02d", months[tm->tm_mon - 1], tm->tm_mday);
3661c3658
<             sprintf((str + 10), " %02d:%02d", tm->tm_hour, tm->tm_min);
---
>             sprintf(str + 10, " %02d:%02d", tm->tm_hour, tm->tm_min);
3673c3670
<                 sprintf((str + strlen(str)), ":%02d.%06d", tm->tm_sec, fsec);
---
>                 sprintf(str + strlen(str), ":%02d.%06d", tm->tm_sec, fsec);
3677c3674
<             if ((fsec != 0) && (tm->tm_year > 0))
---
>             if (fsec != 0 && tm->tm_year > 0)
3679c3676
<                 sprintf((str + strlen(str)), ":%09.6f", tm->tm_sec + fsec);
---
>                 sprintf(str + strlen(str), ":%09.6f", tm->tm_sec + fsec);
3684c3681
<                 sprintf((str + strlen(str)), ":%02d", tm->tm_sec);
---
>                 sprintf(str + strlen(str), ":%02d", tm->tm_sec);
3686,3687c3683,3684
<             sprintf((str + strlen(str)), " %04d",
<                  ((tm->tm_year > 0) ? tm->tm_year : -(tm->tm_year - 1)));
---
>             sprintf(str + strlen(str), " %04d",
>                  (tm->tm_year > 0) ? tm->tm_year : -(tm->tm_year - 1));
3692c3689
<                     sprintf((str + strlen(str)), " %.*s", MAXTZLEN, *tzn);
---
>                     sprintf(str + strlen(str), " %.*s", MAXTZLEN, *tzn);
3703,3704c3700,3701
<                     min = ((abs(*tzp) / 60) % 60);
<                     sprintf((str + strlen(str)), ((min != 0) ? " %+03d:%02d" : " %+03d"), hour, min);
---
>                     min = (abs(*tzp) / 60) % 60;
>                     sprintf(str + strlen(str), (min != 0) ? " %+03d:%02d" : " %+03d", hour, min);
3709c3706
<                 sprintf((str + strlen(str)), " BC");
---
>                 sprintf(str + strlen(str), " BC");
3745c3742
<                         tm->tm_year, ((tm->tm_year != 1) ? "s" : ""));
---
>                         tm->tm_year, (tm->tm_year != 1) ? "s" : "");
3753,3755c3750,3752
<                 sprintf(cp, "%s%s%d mon%s", (is_nonzero ? " " : ""),
<                         ((is_before && (tm->tm_mon > 0)) ? "+" : ""),
<                         tm->tm_mon, ((tm->tm_mon != 1) ? "s" : ""));
---
>                 sprintf(cp, "%s%s%d mon%s", is_nonzero ? " " : "",
>                         (is_before && tm->tm_mon > 0) ? "+" : "",
>                         tm->tm_mon, (tm->tm_mon != 1) ? "s" : "");
3763,3765c3760,3762
<                 sprintf(cp, "%s%s%d day%s", (is_nonzero ? " " : ""),
<                         ((is_before && (tm->tm_mday > 0)) ? "+" : ""),
<                         tm->tm_mday, ((tm->tm_mday != 1) ? "s" : ""));
---
>                 sprintf(cp, "%s%s%d day%s", is_nonzero ? " " : "",
>                         (is_before && tm->tm_mday > 0) ? "+" : "",
>                         tm->tm_mday, (tm->tm_mday != 1) ? "s" : "");
3771,3772c3768,3769
<             if ((!is_nonzero) || (tm->tm_hour != 0) || (tm->tm_min != 0)
<                 || (tm->tm_sec != 0) || (fsec != 0))
---
>             if (!is_nonzero || tm->tm_hour != 0 || tm->tm_min != 0 ||
>                 tm->tm_sec != 0 || fsec != 0)
3774,3775c3771,3772
<                 int            minus = ((tm->tm_hour < 0) || (tm->tm_min < 0)
<                                      || (tm->tm_sec < 0) || (fsec < 0));
---
>                 int            minus = (tm->tm_hour < 0 || tm->tm_min < 0 ||
>                                      tm->tm_sec < 0 || fsec < 0);
3777c3774
<                 sprintf(cp, "%s%s%02d:%02d", (is_nonzero ? " " : ""),
---
>                 sprintf(cp, "%s%s%02d:%02d", is_nonzero ? " " : "",
3819c3816
<                         ((year != 1) ? "s" : ""));
---
>                         (year != 1) ? "s" : "");
3829c3826
<                 if (is_before || ((!is_nonzero) && (tm->tm_mon < 0)))
---
>                 if (is_before || (!is_nonzero && tm->tm_mon < 0))
3832,3833c3829,3830
<                 sprintf(cp, "%s%d mon%s", (is_nonzero ? " " : ""), mon,
<                         ((mon != 1) ? "s" : ""));
---
>                 sprintf(cp, "%s%d mon%s", is_nonzero ? " " : "", mon,
>                         (mon != 1) ? "s" : "");
3844c3841
<                 if (is_before || ((!is_nonzero) && (tm->tm_mday < 0)))
---
>                 if (is_before || (!is_nonzero && tm->tm_mday < 0))
3847,3848c3844,3845
<                 sprintf(cp, "%s%d day%s", (is_nonzero ? " " : ""), day,
<                         ((day != 1) ? "s" : ""));
---
>                 sprintf(cp, "%s%d day%s", is_nonzero ? " " : "", day,
>                         (day != 1) ? "s" : "");
3858c3855
<                 if (is_before || ((!is_nonzero) && (tm->tm_hour < 0)))
---
>                 if (is_before || (!is_nonzero && tm->tm_hour < 0))
3861,3862c3858,3859
<                 sprintf(cp, "%s%d hour%s", (is_nonzero ? " " : ""), hour,
<                         ((hour != 1) ? "s" : ""));
---
>                 sprintf(cp, "%s%d hour%s", is_nonzero ? " " : "", hour,
>                         (hour != 1) ? "s" : "");
3873c3870
<                 if (is_before || ((!is_nonzero) && (tm->tm_min < 0)))
---
>                 if (is_before || (!is_nonzero && tm->tm_min < 0))
3876,3877c3873,3874
<                 sprintf(cp, "%s%d min%s", (is_nonzero ? " " : ""), min,
<                         ((min != 1) ? "s" : ""));
---
>                 sprintf(cp, "%s%d min%s", is_nonzero ? " " : "", min,
>                         (min != 1) ? "s" : "");
3891c3888
<                 if (is_before || ((!is_nonzero) && (tm->tm_sec < 0)))
---
>                 if (is_before || (!is_nonzero && tm->tm_sec < 0))
3897c3894
<                 else if ((!is_nonzero) && (tm->tm_sec == 0) && (fsec < 0))
---
>                 else if (!is_nonzero && tm->tm_sec == 0 && fsec < 0)
3902,3903c3899,3900
<                 sprintf(cp, "%s%d.%02d secs", (is_nonzero ? " " : ""),
<                         tm->tm_sec, (((int) sec) / 10000));
---
>                 sprintf(cp, "%s%d.%02d secs", is_nonzero ? " " : "",
>                         tm->tm_sec, ((int) sec) / 10000);
3908c3905
<                 if (is_before || ((!is_nonzero) && (fsec < 0)))
---
>                 if (is_before || (!is_nonzero && fsec < 0))
3911c3908
<                 sprintf(cp, "%s%.2f secs", (is_nonzero ? " " : ""), sec);
---
>                 sprintf(cp, "%s%.2f secs", is_nonzero ? " " : "", sec);
3923c3920
<                 if (is_before || ((!is_nonzero) && (tm->tm_sec < 0)))
---
>                 if (is_before || (!is_nonzero && tm->tm_sec < 0))
3926,3927c3923,3924
<                 sprintf(cp, "%s%d sec%s", (is_nonzero ? " " : ""), sec,
<                         ((sec != 1) ? "s" : ""));
---
>                 sprintf(cp, "%s%d sec%s", is_nonzero ? " " : "", sec,
>                         (sec != 1) ? "s" : "");
Index: timestamp.c
===================================================================
RCS file: /cvsroot/pgsql/src/backend/utils/adt/timestamp.c,v
retrieving revision 1.119
diff -r1.119 timestamp.c
267c267
<         if ((typmod < 0) || (typmod > MAX_TIMESTAMP_PRECISION))
---
>         if (typmod < 0 || typmod > MAX_TIMESTAMP_PRECISION)
581c581
<     interval  ->time = pq_getmsgint64(buf);
---
>     interval->time = pq_getmsgint64(buf);
584c584
<     interval  ->time = pq_getmsgfloat8(buf);
---
>     interval->time = pq_getmsgfloat8(buf);
586c586
<     interval  ->month = pq_getmsgint(buf, sizeof(interval->month));
---
>     interval->month = pq_getmsgint(buf, sizeof(interval->month));
681,682c681,682
<             interval  ->month = ((interval->month / 12) *12);
<             interval  ->time = 0;
---
>             interval->month = (interval->month / 12) * 12;
>             interval->time = 0;
686,687c686,687
<             interval  ->month %= 12;
<             interval  ->time = 0;
---
>             interval->month %= 12;
>             interval->time = 0;
691c691
<             interval  ->time = 0;
---
>             interval->time = 0;
695c695
<             interval  ->month = 0;
---
>             interval->month = 0;
698,699c698,699
<             interval  ->time = (((int) (interval->time / INT64CONST(86400000000)))
<                                 * INT64CONST(86400000000));
---
>             interval->time = ((int) (interval->time / INT64CONST(86400000000))) *
>                                 INT64CONST(86400000000);
702c702
<             interval  ->time = (((int) (interval->time / 86400)) * 86400);
---
>             interval->time = ((int) (interval->time / 86400)) * 86400;
714c714
<             interval  ->month = 0;
---
>             interval->month = 0;
717,720c717,720
<             day = (interval->time / INT64CONST(86400000000));
<             interval  ->time -= (day * INT64CONST(86400000000));
<             interval  ->time = ((interval->time / INT64CONST(3600000000))
<                                 *INT64CONST(3600000000));
---
>             day = interval->time / INT64CONST(86400000000);
>             interval->time -= day * INT64CONST(86400000000);
>             interval->time = (interval->time / INT64CONST(3600000000)) *
>                                 INT64CONST(3600000000);
724c724
<             interval  ->time = (((int) (interval->time / 3600)) * 3600.0);
---
>             interval->time = ((int) (interval->time / 3600)) * 3600.0;
736c736
<             interval  ->month = 0;
---
>             interval->month = 0;
739,742c739,742
<             hour = (interval->time / INT64CONST(3600000000));
<             interval  ->time -= (hour * INT64CONST(3600000000));
<             interval  ->time = ((interval->time / INT64CONST(60000000))
<                                 *INT64CONST(60000000));
---
>             hour = interval->time / INT64CONST(3600000000);
>             interval->time -= hour * INT64CONST(3600000000);
>             interval->time = (interval->time / INT64CONST(60000000)) *
>                                 INT64CONST(60000000);
746c746
<             interval  ->time = (((int) (interval->time / 60)) * 60);
---
>             interval->time = ((int) (interval->time / 60)) * 60;
758c758
<             interval  ->month = 0;
---
>             interval->month = 0;
761,762c761,762
<             minute = (interval->time / INT64CONST(60000000));
<             interval  ->time -= (minute * INT64CONST(60000000));
---
>             minute = interval->time / INT64CONST(60000000);
>             interval->time -= minute * INT64CONST(60000000);
773c773
<             interval  ->month = 0;
---
>             interval->month = 0;
776,777c776,777
<             interval  ->time = ((interval->time / INT64CONST(3600000000))
<                                 *INT64CONST(3600000000));
---
>             interval->time = (interval->time / INT64CONST(3600000000)) *
>                                 INT64CONST(3600000000);
780c780
<             interval  ->time = (((int) (interval->time / 3600)) * 3600);
---
>             interval->time = ((int) (interval->time / 3600)) * 3600;
788c788
<             interval  ->month = 0;
---
>             interval->month = 0;
791,792c791,792
<             interval  ->time = ((interval->time / INT64CONST(60000000))
<                                 *INT64CONST(60000000));
---
>             interval->time = (interval->time / INT64CONST(60000000)) *
>                                 INT64CONST(60000000);
795c795
<             interval  ->time = (((int) (interval->time / 60)) * 60);
---
>             interval->time = ((int) (interval->time / 60)) * 60;
803c803
<             interval  ->month = 0;
---
>             interval->month = 0;
816c816
<             interval  ->month = 0;
---
>             interval->month = 0;
820,822c820,822
<             interval  ->time -= (day * INT64CONST(86400000000));
<             interval  ->time = ((interval->time / INT64CONST(60000000))
<                                 *INT64CONST(60000000));
---
>             interval->time -= day * INT64CONST(86400000000);
>             interval->time = (interval->time / INT64CONST(60000000)) *
>                                 INT64CONST(60000000);
826c826
<             interval  ->time = (((int) (interval->time / 60)) * 60);
---
>             interval->time = ((int) (interval->time / 60)) * 60;
841c841
<             interval  ->month = 0;
---
>             interval->month = 0;
844,845c844,845
<             day = (interval->time / INT64CONST(86400000000));
<             interval  ->time -= (day * INT64CONST(86400000000));
---
>             day = interval->time / INT64CONST(86400000000);
>             interval->time -= day * INT64CONST(86400000000);
862c862
<             interval  ->month = 0;
---
>             interval->month = 0;
865,867c865,866
<             hour = (interval->time / INT64CONST(3600000000));
<             interval  ->time -= (hour * INT64CONST(3600000000));
<
---
>             hour = interval->time / INT64CONST(3600000000);
>             interval->time -= hour * INT64CONST(3600000000);
878c877
<             if ((precision < 0) || (precision > MAX_INTERVAL_PRECISION))
---
>             if (precision < 0 || precision > MAX_INTERVAL_PRECISION)
895,896c894,897
<                 interval  ->time = (((interval->time + IntervalOffsets[precision]) /IntervalScales[precision])
<                                     * IntervalScales[precision]);
---
>                 interval->time = (((interval->time +
>                                     IntervalOffsets[precision]) /
>                                     IntervalScales[precision]) *
>                                     IntervalScales[precision];
900,901c901,904
<                 interval  ->time = -(((-interval->time + IntervalOffsets[precision]) /IntervalScales[precision])
<                                      * IntervalScales[precision]);
---
>                 interval->time = -(((-interval->time +
>                                     IntervalOffsets[precision]) /
>                                     IntervalScales[precision]) *
>                                     IntervalScales[precision]);
904,905c907,909
<             interval  ->time = (rint(((double) interval->time) *IntervalScales[precision])
<                                 / IntervalScales[precision]);
---
>             interval->time = rint(((double) interval->time) *
>                                     IntervalScales[precision]) /
>                                     IntervalScales[precision];
957,967c961,971
<     *hour = (time / INT64CONST(3600000000));
<     time -= ((*hour) * INT64CONST(3600000000));
<     *min = (time / INT64CONST(60000000));
<     time -= ((*min) * INT64CONST(60000000));
<     *sec = (time / INT64CONST(1000000));
<     *fsec = (time - (*sec * INT64CONST(1000000)));
< #else
<     *hour = (time / 3600);
<     time -= ((*hour) * 3600);
<     *min = (time / 60);
<     time -= ((*min) * 60);
---
>     *hour = time / INT64CONST(3600000000);
>     time -= (*hour) * INT64CONST(3600000000);
>     *min = time / INT64CONST(60000000);
>     time -= (*min) * INT64CONST(60000000);
>     *sec = time / INT64CONST(1000000);
>     *fsec = time - (*sec * INT64CONST(1000000));
> #else
>     *hour = time / 3600;
>     time -= (*hour) * 3600;
>     *min = time / 60;
>     time -= (*min) * 60;
1013c1017
<         date      -=1;
---
>         date -= 1;
1021c1025
<         date      -=1;
---
>         date -=1;
1141c1145
<     *result = (date *INT64CONST(86400000000)) +time;
---
>     *result = date * INT64CONST(86400000000) + time;
1146c1150,1151
<     if ((*result < 0) ? (date >=0) : (date <0))
---
>     if ((*result < 0 && date >= 0) ||
>         (*result >= 0 && date < 0))
1149c1154
<     *result = ((date *86400) +time);
---
>     *result = date * 86400 + time;
1208c1213
<     span->month = ((tm->tm_year * 12) + tm->tm_mon);
---
>     span->month = tm->tm_year * 12 + tm->tm_mon;
1614c1619
<         span1 += ((interval1->month * INT64CONST(30) * INT64CONST(86400000000)));
---
>         span1 += interval1->month * INT64CONST(30) * INT64CONST(86400000000);
1616c1621
<         span2 += ((interval2->month * INT64CONST(30) * INT64CONST(86400000000)));
---
>         span2 += interval2->month * INT64CONST(30) * INT64CONST(86400000000);
1619c1624
<         span1 += (interval1->month * (30.0 * 86400));
---
>         span1 += interval1->month * (30.0 * 86400);
1621c1626
<         span2 += (interval2->month * (30.0 * 86400));
---
>         span2 += interval2->month * (30.0 * 86400);
2158,2159c2163,2164
<     result->time += ((months - result->month) * INT64CONST(30)
<                      * INT64CONST(86400000000));
---
>     result->time += (months - result->month) * INT64CONST(30) *
>                     INT64CONST(86400000000);
2202,2203c2207,2208
<     result->time += (((span->month - (result->month * factor))
<                    * INT64CONST(30) * INT64CONST(86400000000)) / factor);
---
>     result->time += ((span->month - (result->month * factor)) *
>                     INT64CONST(30) * INT64CONST(86400000000)) / factor;
2205c2210
<     months = (span->month / factor);
---
>     months = span->month / factor;
2331,2332c2336,2337
<     if ((timestamp2tm(dt1, NULL, tm1, &fsec1, NULL) == 0)
<         && (timestamp2tm(dt2, NULL, tm2, &fsec2, NULL) == 0))
---
>     if (timestamp2tm(dt1, NULL, tm1, &fsec1, NULL) == 0 &&
>         timestamp2tm(dt2, NULL, tm2, &fsec2, NULL) == 0)
2445,2446c2450,2451
<     if ((timestamp2tm(dt1, &tz1, tm1, &fsec1, &tzn) == 0)
<         && (timestamp2tm(dt2, &tz2, tm2, &fsec2, &tzn) == 0))
---
>     if (timestamp2tm(dt1, &tz1, tm1, &fsec1, &tzn) == 0 &&
>         timestamp2tm(dt2, &tz2, tm2, &fsec2, &tzn) == 0)
2813c2818
<                 fsec = ((fsec / 1000) * 1000);
---
>                 fsec = (fsec / 1000) * 1000;
3153c3158
<     if (dayn < (day4 - day0))
---
>     if (dayn < day4 - day0)
3161c3166
<     result = (((dayn - (day4 - day0)) / 7) + 1);
---
>     result = (dayn - (day4 - day0)) / 7 + 1;
3174,3175c3179,3180
<         if (dayn >= (day4 - day0))
<             result = (((dayn - (day4 - day0)) / 7) + 1);
---
>         if (dayn >= day4 - day0)
>             result = (dayn - (day4 - day0)) / 7 + 1;
3207c3212
<     if (dayn < (day4 - day0))
---
>     if (dayn < day4 - day0)
3217c3222
<     result = (((dayn - (day4 - day0)) / 7) + 1);
---
>     result = (dayn - (day4 - day0)) / 7 + 1;
3230c3235
<         if (dayn >= (day4 - day0))
---
>         if (dayn >= day4 - day0)
3279c3284
<                 result = ((tm->tm_sec * 1000000e0) + fsec);
---
>                 result = tm->tm_sec * 1000000e0 + fsec;
3287c3292
<                 result = ((tm->tm_sec * 1000e0) + (fsec / 1000e0));
---
>                 result = tm->tm_sec * 1000e0 + fsec / 1000e0;
3295c3300
<                 result = (tm->tm_sec + (fsec / 1000000e0));
---
>                 result = tm->tm_sec + fsec / 1000000e0;
3297c3302
<                 result = (tm->tm_sec + fsec);
---
>                 result = tm->tm_sec + fsec;
3318c3323
<                 result = ((tm->tm_mon - 1) / 3) + 1;
---
>                 result = (tm->tm_mon - 1) / 3 + 1;
3348,3351c3353,3357
<                 /*
<                  * centuries AD, c>0: year in [ (c-1)*100+1 :      c*100 ]
<                  * centuries BC, c<0: year in [        c*100    : (c+1)*100-1
<                  * ] there is no number 0 century.
---
>                 /* ----
>                  * centuries AD, c>0: year in [ (c-1)* 100 + 1 : c*100 ]
>                  * centuries BC, c<0: year in [ c*100 : (c+1) * 100 - 1]
>                  * there is no number 0 century.
>                  * ----
3371,3372c3377,3378
<                 result += (((((tm->tm_hour * 60) + tm->tm_min) * 60)
<                             + tm->tm_sec + (fsec / 1000000e0)) / 86400e0);
---
>                 result += ((((tm->tm_hour * 60) + tm->tm_min) * 60) +
>                             tm->tm_sec + (fsec / 1000000e0)) / 86400e0;
3374,3375c3380,3381
<                 result += (((((tm->tm_hour * 60) + tm->tm_min) * 60)
<                             + tm->tm_sec + fsec) / 86400e0);
---
>                 result += ((((tm->tm_hour * 60) + tm->tm_min) * 60) +
>                             tm->tm_sec + fsec) / 86400e0;
3518c3524
<                 result = ((tm->tm_sec * 1000000e0) + fsec);
---
>                 result = tm->tm_sec * 1000000e0 + fsec;
3526c3532
<                 result = ((tm->tm_sec * 1000e0) + (fsec / 1000e0));
---
>                 result = tm->tm_sec * 1000e0 + fsec / 1000e0;
3534c3540
<                 result = (tm->tm_sec + (fsec / 1000000e0));
---
>                 result = tm->tm_sec + fsec / 1000000e0;
3536c3542
<                 result = (tm->tm_sec + fsec);
---
>                 result = tm->tm_sec + fsec;
3557c3563
<                 result = ((tm->tm_mon - 1) / 3) + 1;
---
>                 result = (tm->tm_mon - 1) / 3 + 1;
3583c3589
<                     result = ((tm->tm_year + 99) / 100);
---
>                     result = (tm->tm_year + 99) / 100;
3591c3597
<                     result = ((tm->tm_year + 999) / 1000);
---
>                     result = (tm->tm_year + 999) / 1000;
3599,3600c3605,3606
<                 result += (((((tm->tm_hour * 60) + tm->tm_min) * 60)
<                             + tm->tm_sec + (fsec / 1000000e0)) / 86400e0);
---
>                 result += ((((tm->tm_hour * 60) + tm->tm_min) * 60) +
>                             tm->tm_sec + (fsec / 1000000e0)) / 86400e0;
3602,3603c3608,3609
<                 result += (((((tm->tm_hour * 60) + tm->tm_min) * 60)
<                             + tm->tm_sec + fsec) / 86400e0);
---
>                 result += ((((tm->tm_hour * 60) + tm->tm_min) * 60) +
>                             tm->tm_sec + fsec) / 86400e0;
3622c3628
<                 result = ((timestamp -SetEpochTimestamp()) /1000000e0);
---
>                 result = (timestamp - SetEpochTimestamp()) /1000000e0;
3624c3630
<                 result = timestamp -SetEpochTimestamp();
---
>                 result = timestamp - SetEpochTimestamp();
3699c3705
<                     result = ((tm->tm_sec * 1000000e0) + fsec);
---
>                     result = tm->tm_sec * 1000000e0 + fsec;
3707c3713
<                     result = ((tm->tm_sec * 1000e0) + (fsec / 1000e0));
---
>                     result = tm->tm_sec * 1000e0 + fsec / 1000e0;
3715c3721
<                     result = (tm->tm_sec + (fsec / 1000000e0));
---
>                     result = tm->tm_sec + fsec / 1000000e0;
3717c3723
<                     result = (tm->tm_sec + fsec);
---
>                     result = tm->tm_sec + fsec;
3776c3782
<     else if ((type == RESERV) && (val == DTK_EPOCH))
---
>     else if (type == RESERV && val == DTK_EPOCH)
3779c3785
<         result = (interval->time / 1000000e0);
---
>         result = interval->time / 1000000e0;
3785,3786c3791,3792
<             result += ((365.25 * 86400) * (interval->month / 12));
<             result += ((30.0 * 86400) * (interval->month % 12));
---
>             result += (365.25 * 86400) * (interval->month / 12);
>             result += (30.0 * 86400) * (interval->month % 12);
3828c3834
<     if ((type == TZ) || (type == DTZ))
---
>     if (type == TZ || type == DTZ)
3869c3875
<     tz = (zone->time / INT64CONST(1000000));
---
>     tz = zone->time / INT64CONST(1000000);
3871c3877
<     tz = (zone->time);
---
>     tz = zone->time;
3977c3983
<     if ((type == TZ) || (type == DTZ))
---
>     if (type == TZ || type == DTZ)