*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.140 2005/05/21 03:38:05 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.141 2005/05/23 17:13:14 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#if 0
/* chop off trailing one to cope with interval rounding */
- if (strcmp((str + len - 4), "0001") == 0)
+ if (strcmp(str + len - 4, "0001") == 0)
{
len -= 4;
*(str + len) = '\0';
#endif
/* chop off trailing zeros... but leave at least 2 fractional digits */
- while ((*(str + len - 1) == '0')
- && (*(str + len - 3) != '.'))
+ while (*(str + len - 1) == '0' && *(str + len - 3) != '.')
{
len--;
*(str + len) = '\0';
*lp++ = *cp++;
}
/* date field? allow embedded text month */
- else if ((*cp == '-') || (*cp == '/') || (*cp == '.'))
+ else if (*cp == '-' || *cp == '/' || *cp == '.')
{
/* save delimiting character to use later */
char delim = *cp;
{
ftype[nf] = DTK_DATE;
*lp++ = *cp++;
- while (isdigit((unsigned char) *cp) || (*cp == delim))
+ while (isdigit((unsigned char) *cp) || *cp == delim)
*lp++ = *cp++;
}
}
else
{
ftype[nf] = DTK_DATE;
- while (isalnum((unsigned char) *cp) || (*cp == delim))
+ while (isalnum((unsigned char) *cp) || *cp == delim)
*lp++ = pg_tolower((unsigned char) *cp++);
}
}
* Full date string with leading text month? Could also be a
* POSIX time zone...
*/
- if ((*cp == '-') || (*cp == '/') || (*cp == '.'))
+ if (*cp == '-' || *cp == '/' || *cp == '.')
{
char delim = *cp;
ftype[nf] = DTK_DATE;
*lp++ = *cp++;
- while (isdigit((unsigned char) *cp) || (*cp == delim))
+ while (isdigit((unsigned char) *cp) || *cp == delim)
*lp++ = *cp++;
}
}
/* sign? then special or numeric timezone */
- else if ((*cp == '+') || (*cp == '-'))
+ else if (*cp == '+' || *cp == '-')
{
*lp++ = *cp++;
/* soak up leading whitespace */
ftype[nf] = DTK_TZ;
*lp++ = *cp++;
while (isdigit((unsigned char) *cp) ||
- (*cp == ':') || (*cp == '.'))
+ *cp == ':' || *cp == '.')
*lp++ = *cp++;
}
/* special? */
* a run-together time with trailing time zone (e.g. hhmmss-zz).
* - thomas 2001-12-25
***/
- else if (((fmask & DTK_DATE_M) == DTK_DATE_M)
- || (ptype != 0))
+ else if ((fmask & DTK_DATE_M) == DTK_DATE_M || ptype != 0)
{
/* No time zone accepted? Then quit... */
if (tzp == NULL)
* second field of a POSIX time: EST+3 (equivalent to
* PST)
*/
- 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]))
{
*tzp -= tz;
tmask = 0;
* already have a month and hour? then assume
* minutes
*/
- if (((fmask & DTK_M(MONTH)) != 0)
- && ((fmask & DTK_M(HOUR)) != 0))
+ if ((fmask & DTK_M(MONTH)) != 0 &&
+ (fmask & DTK_M(HOUR)) != 0)
{
tm->tm_min = val;
tmask = DTK_M(MINUTE);
tmask |= DTK_TIME_M;
#ifdef HAVE_INT64_TIMESTAMP
- 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);
#else
- 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);
#endif
}
break;
cp = strchr(field[i], '.');
/* Embedded decimal and no date yet? */
- if ((cp != NULL) && !(fmask & DTK_DATE_M))
+ if (cp != NULL && !(fmask & DTK_DATE_M))
{
dterr = DecodeDate(field[i], fmask, &tmask, tm);
if (dterr)
return dterr;
}
/* embedded decimal and several digits before? */
- else if ((cp != NULL) && ((flen - strlen(cp)) > 2))
+ else if (cp != NULL && flen - strlen(cp) > 2)
{
/*
* Interpret as a concatenated date or time Set
tmask = DTK_DATE_M;
*dtype = DTK_DATE;
GetCurrentDateTime(tm);
- 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);
tm->tm_hour = 0;
tm->tm_min = 0;
tm->tm_sec = 0;
tmask = DTK_DATE_M;
*dtype = DTK_DATE;
GetCurrentDateTime(tm);
- 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);
tm->tm_hour = 0;
tm->tm_min = 0;
tm->tm_sec = 0;
* already have a (numeric) month? then see if we
* can substitute...
*/
- 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)
{
tm->tm_mday = tm->tm_mon;
tmask = DTK_M(DAY);
* DTK_TIME should be hh:mm:ss.fff
* DTK_DATE should be hhmmss-zz
***/
- 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))
return DTERR_BAD_FORMAT;
ptype = val;
return DTERR_MD_FIELD_OVERFLOW;
}
- if ((mer != HR24) && (tm->tm_hour > 12))
+ if (mer != HR24 && tm->tm_hour > 12)
return DTERR_FIELD_OVERFLOW;
- if ((mer == AM) && (tm->tm_hour == 12))
+ if (mer == AM && tm->tm_hour == 12)
tm->tm_hour = 0;
- else if ((mer == PM) && (tm->tm_hour != 12))
+ else if (mer == PM && tm->tm_hour != 12)
tm->tm_hour += 12;
/* do additional checking for full date specs... */
* Form the candidate pg_time_t values with local-time adjustment
*/
beforetime = mytime - before_gmtoff;
- 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))
goto overflow;
aftertime = mytime - after_gmtoff;
- 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))
goto overflow;
/*
return DTERR_BAD_FORMAT;
/* Under limited circumstances, we will accept a date... */
- 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))
{
dterr = DecodeDate(field[i], fmask, &tmask, tm);
if (dterr)
* second field of a POSIX time: EST+3 (equivalent to
* PST)
*/
- 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]))
{
*tzp -= tz;
tmask = 0;
* already have a month and hour? then assume
* minutes
*/
- if (((fmask & DTK_M(MONTH)) != 0)
- && ((fmask & DTK_M(HOUR)) != 0))
+ if ((fmask & DTK_M(MONTH)) != 0 &&
+ (fmask & DTK_M(HOUR)) != 0)
{
tm->tm_min = val;
tmask = DTK_M(MINUTE);
tmask |= DTK_TIME_M;
#ifdef HAVE_INT64_TIMESTAMP
- dt2time((time * INT64CONST(86400000000)),
+ dt2time(time * INT64CONST(86400000000),
&tm->tm_hour, &tm->tm_min, &tm->tm_sec, fsec);
#else
- dt2time((time * 86400),
+ dt2time(time * 86400,
&tm->tm_hour, &tm->tm_min, &tm->tm_sec, fsec);
#endif
}
* Under limited circumstances, we will accept a
* date...
*/
- if ((i == 0) && ((nf >= 2) && (ftype[nf - 1] == DTK_DATE)))
+ if (i == 0 && nf >= 2 && ftype[nf - 1] == DTK_DATE)
{
dterr = DecodeDate(field[i], fmask, &tmask, tm);
if (dterr)
return dterr;
}
/* embedded decimal and several digits before? */
- else if ((flen - strlen(cp)) > 2)
+ else if (flen - strlen(cp) > 2)
{
/*
* Interpret as a concatenated date or time
* DTK_TIME should be hh:mm:ss.fff
* DTK_DATE should be hhmmss-zz
***/
- 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))
return DTERR_BAD_FORMAT;
ptype = val;
fmask |= tmask;
}
- if ((mer != HR24) && (tm->tm_hour > 12))
+ if (mer != HR24 && tm->tm_hour > 12)
return DTERR_FIELD_OVERFLOW;
- if ((mer == AM) && (tm->tm_hour == 12))
+ if (mer == AM && tm->tm_hour == 12)
tm->tm_hour = 0;
- else if ((mer == PM) && (tm->tm_hour != 12))
+ else if (mer == PM && tm->tm_hour != 12)
tm->tm_hour += 12;
#ifdef HAVE_INT64_TIMESTAMP
- 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))
return DTERR_FIELD_OVERFLOW;
#else
- 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)
return DTERR_FIELD_OVERFLOW;
#endif
char *field[MAXDATEFIELDS];
/* parse this string... */
- while ((*str != '\0') && (nf < MAXDATEFIELDS))
+ while (*str != '\0' && nf < MAXDATEFIELDS)
{
/* skip field separators */
while (!isalnum((unsigned char) *str))
/* do a sanity check */
#ifdef HAVE_INT64_TIMESTAMP
- 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))
return DTERR_FIELD_OVERFLOW;
#else
- 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)
return DTERR_FIELD_OVERFLOW;
#endif
* More than two digits before decimal point? Then could be a date
* or a run-together time: 2001.360 20011225 040506.789
*/
- if ((cp - str) > 2)
+ if (cp - str > 2)
{
dterr = DecodeNumberField(flen, str,
(fmask | DTK_DATE_M),
return DTERR_BAD_FORMAT;
/* Special case for day of year */
- 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)
{
*tmask = (DTK_M(DOY) | DTK_M(MONTH) | DTK_M(DAY));
tm->tm_yday = val;
if (*str != '+' && *str != '-')
return DTERR_BAD_FORMAT;
- hr = strtol((str + 1), &cp, 10);
+ hr = strtol(str + 1, &cp, 10);
/* explicit delimiter? */
if (*cp == ':')
- min = strtol((cp + 1), &cp, 10);
+ min = strtol(cp + 1, &cp, 10);
/* otherwise, might have run things together... */
- else if ((*cp == '\0') && (strlen(str) > 3))
+ else if (*cp == '\0' && strlen(str) > 3)
{
min = hr % 100;
hr = hr / 100;
else
min = 0;
- if ((hr < 0) || (hr > 13))
+ if (hr < 0 || hr > 13)
return DTERR_TZDISP_OVERFLOW;
- if ((min < 0) || (min >= 60))
+ if (min < 0 || min >= 60)
return DTERR_TZDISP_OVERFLOW;
tz = (hr * 60 + min) * 60;
int type;
datetkn *tp;
- if ((datecache[field] != NULL)
- && (strncmp(lowtoken, datecache[field]->token, TOKMAXLEN) == 0))
+ if (datecache[field] != NULL &&
+ strncmp(lowtoken, datecache[field]->token, TOKMAXLEN) == 0)
tp = datecache[field];
else
{
* Timezone is a token with a leading sign character and
* otherwise the same as a non-signed time field
*/
- Assert((*field[i] == '-') || (*field[i] == '+'));
+ Assert(*field[i] == '-' || *field[i] == '+');
/*
* A single signed number ends up here, but will be
* through to DTK_NUMBER, which *can* tolerate this.
*/
cp = field[i] + 1;
- while ((*cp != '\0') && (*cp != ':') && (*cp != '.'))
+ while (*cp != '\0' && *cp != ':' && *cp != '.')
cp++;
- if ((*cp == ':') &&
- (DecodeTime(field[i] + 1, fmask, &tmask, tm, fsec) == 0))
+ if (*cp == ':' &&
+ DecodeTime(field[i] + 1, fmask, &tmask, tm, fsec) == 0)
{
if (*field[i] == '-')
{
*fsec += (fval - sec);
#endif
}
- tmask = ((fmask & DTK_M(DAY)) ? 0 : DTK_M(DAY));
+ tmask = (fmask & DTK_M(DAY)) ? 0 : DTK_M(DAY);
break;
case DTK_WEEK:
*fsec += (fval - sec);
#endif
}
- tmask = ((fmask & DTK_M(DAY)) ? 0 : DTK_M(DAY));
+ tmask = (fmask & DTK_M(DAY)) ? 0 : DTK_M(DAY);
break;
case DTK_MONTH:
tm->tm_year += val;
if (fval != 0)
tm->tm_mon += (fval * 12);
- tmask = ((fmask & DTK_M(YEAR)) ? 0 : DTK_M(YEAR));
+ tmask = (fmask & DTK_M(YEAR)) ? 0 : DTK_M(YEAR);
break;
case DTK_DECADE:
tm->tm_year += val * 10;
if (fval != 0)
tm->tm_mon += (fval * 120);
- tmask = ((fmask & DTK_M(YEAR)) ? 0 : DTK_M(YEAR));
+ tmask = (fmask & DTK_M(YEAR)) ? 0 : DTK_M(YEAR);
break;
case DTK_CENTURY:
tm->tm_year += val * 100;
if (fval != 0)
tm->tm_mon += (fval * 1200);
- tmask = ((fmask & DTK_M(YEAR)) ? 0 : DTK_M(YEAR));
+ tmask = (fmask & DTK_M(YEAR)) ? 0 : DTK_M(YEAR);
break;
case DTK_MILLENNIUM:
tm->tm_year += val * 1000;
if (fval != 0)
tm->tm_mon += (fval * 12000);
- tmask = ((fmask & DTK_M(YEAR)) ? 0 : DTK_M(YEAR));
+ tmask = (fmask & DTK_M(YEAR)) ? 0 : DTK_M(YEAR);
break;
default:
int type;
datetkn *tp;
- if ((deltacache[field] != NULL)
- && (strncmp(lowtoken, deltacache[field]->token, TOKMAXLEN) == 0))
+ if (deltacache[field] != NULL &&
+ strncmp(lowtoken, deltacache[field]->token, TOKMAXLEN) == 0)
tp = deltacache[field];
else
tp = datebsearch(lowtoken, deltatktbl, szdeltatktbl);
else
{
type = tp->type;
- if ((type == TZ) || (type == DTZ))
+ if (type == TZ || type == DTZ)
*val = FROMVAL(tp);
else
*val = tp->value;
int
EncodeDateOnly(struct pg_tm * tm, int style, char *str)
{
- if ((tm->tm_mon < 1) || (tm->tm_mon > 12))
+ if (tm->tm_mon < 1 || tm->tm_mon > 12)
return -1;
switch (style)
else
sprintf(str, "%02d/%02d", tm->tm_mon, tm->tm_mday);
if (tm->tm_year > 0)
- sprintf((str + 5), "/%04d", tm->tm_year);
+ sprintf(str + 5, "/%04d", tm->tm_year);
else
- sprintf((str + 5), "/%04d %s", -(tm->tm_year - 1), "BC");
+ sprintf(str + 5, "/%04d %s", -(tm->tm_year - 1), "BC");
break;
case USE_GERMAN_DATES:
/* German-style date format */
sprintf(str, "%02d.%02d", tm->tm_mday, tm->tm_mon);
if (tm->tm_year > 0)
- sprintf((str + 5), ".%04d", tm->tm_year);
+ sprintf(str + 5, ".%04d", tm->tm_year);
else
- sprintf((str + 5), ".%04d %s", -(tm->tm_year - 1), "BC");
+ sprintf(str + 5, ".%04d %s", -(tm->tm_year - 1), "BC");
break;
case USE_POSTGRES_DATES:
else
sprintf(str, "%02d-%02d", tm->tm_mon, tm->tm_mday);
if (tm->tm_year > 0)
- sprintf((str + 5), "-%04d", tm->tm_year);
+ sprintf(str + 5, "-%04d", tm->tm_year);
else
- sprintf((str + 5), "-%04d %s", -(tm->tm_year - 1), "BC");
+ sprintf(str + 5, "-%04d %s", -(tm->tm_year - 1), "BC");
break;
}
int
EncodeTimeOnly(struct pg_tm * tm, fsec_t fsec, int *tzp, int style, char *str)
{
- if ((tm->tm_hour < 0) || (tm->tm_hour > 24))
+ if (tm->tm_hour < 0 || tm->tm_hour > 24)
return -1;
sprintf(str, "%02d:%02d", tm->tm_hour, tm->tm_min);
if (fsec != 0)
{
#ifdef HAVE_INT64_TIMESTAMP
- sprintf((str + strlen(str)), ":%02d.%06d", tm->tm_sec, fsec);
+ sprintf(str + strlen(str), ":%02d.%06d", tm->tm_sec, fsec);
#else
- sprintf((str + strlen(str)), ":%013.10f", tm->tm_sec + fsec);
+ sprintf(str + strlen(str), ":%013.10f", tm->tm_sec + fsec);
#endif
/* chop off trailing pairs of zeros... */
- while ((strcmp((str + strlen(str) - 2), "00") == 0)
- && (*(str + strlen(str) - 3) != '.'))
+ while (strcmp((str + strlen(str) - 2), "00") == 0 &&
+ *(str + strlen(str) - 3) != '.')
*(str + strlen(str) - 2) = '\0';
}
else
- sprintf((str + strlen(str)), ":%02d", tm->tm_sec);
+ sprintf(str + strlen(str), ":%02d", tm->tm_sec);
if (tzp != NULL)
{
min;
hour = -(*tzp / 3600);
- 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);
}
return TRUE;
/*
* Why are we checking only the month field? Change this to an
- * assert... if ((tm->tm_mon < 1) || (tm->tm_mon > 12)) return -1;
+ * assert... if (tm->tm_mon < 1 || tm->tm_mon > 12) return -1;
*/
- Assert((tm->tm_mon >= 1) && (tm->tm_mon <= 12));
+ Assert(tm->tm_mon >= 1 && tm->tm_mon <= 12);
switch (style)
{
/* Compatible with ISO-8601 date formats */
sprintf(str, "%04d-%02d-%02d %02d:%02d",
- ((tm->tm_year > 0) ? tm->tm_year : -(tm->tm_year - 1)),
+ (tm->tm_year > 0) ? tm->tm_year : -(tm->tm_year - 1),
tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min);
/*
#ifdef HAVE_INT64_TIMESTAMP
if (fsec != 0)
{
- sprintf((str + strlen(str)), ":%02d.%06d", tm->tm_sec, fsec);
+ sprintf(str + strlen(str), ":%02d.%06d", tm->tm_sec, fsec);
TrimTrailingZeros(str);
}
#else
- if ((fsec != 0) && (tm->tm_year > 0))
+ if (fsec != 0 && tm->tm_year > 0)
{
- sprintf((str + strlen(str)), ":%09.6f", tm->tm_sec + fsec);
+ sprintf(str + strlen(str), ":%09.6f", tm->tm_sec + fsec);
TrimTrailingZeros(str);
}
#endif
else
- sprintf((str + strlen(str)), ":%02d", tm->tm_sec);
+ sprintf(str + strlen(str), ":%02d", tm->tm_sec);
/*
* tzp == NULL indicates that we don't want *any* time zone
if (tzp != NULL && tm->tm_isdst >= 0)
{
hour = -(*tzp / 3600);
- 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);
}
if (tm->tm_year <= 0)
- sprintf((str + strlen(str)), " BC");
+ sprintf(str + strlen(str), " BC");
break;
case USE_SQL_DATES:
else
sprintf(str, "%02d/%02d", tm->tm_mon, tm->tm_mday);
- 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),
tm->tm_hour, tm->tm_min);
/*
#ifdef HAVE_INT64_TIMESTAMP
if (fsec != 0)
{
- sprintf((str + strlen(str)), ":%02d.%06d", tm->tm_sec, fsec);
+ sprintf(str + strlen(str), ":%02d.%06d", tm->tm_sec, fsec);
TrimTrailingZeros(str);
}
#else
- if ((fsec != 0) && (tm->tm_year > 0))
+ if (fsec != 0 && tm->tm_year > 0)
{
- sprintf((str + strlen(str)), ":%09.6f", tm->tm_sec + fsec);
+ sprintf(str + strlen(str), ":%09.6f", tm->tm_sec + fsec);
TrimTrailingZeros(str);
}
#endif
else
- sprintf((str + strlen(str)), ":%02d", tm->tm_sec);
+ sprintf(str + strlen(str), ":%02d", tm->tm_sec);
if (tzp != NULL && tm->tm_isdst >= 0)
{
if (*tzn != NULL)
- sprintf((str + strlen(str)), " %.*s", MAXTZLEN, *tzn);
+ sprintf(str + strlen(str), " %.*s", MAXTZLEN, *tzn);
else
{
hour = -(*tzp / 3600);
- 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);
}
}
if (tm->tm_year <= 0)
- sprintf((str + strlen(str)), " BC");
+ sprintf(str + strlen(str), " BC");
break;
case USE_GERMAN_DATES:
sprintf(str, "%02d.%02d", tm->tm_mday, tm->tm_mon);
- 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),
tm->tm_hour, tm->tm_min);
/*
#ifdef HAVE_INT64_TIMESTAMP
if (fsec != 0)
{
- sprintf((str + strlen(str)), ":%02d.%06d", tm->tm_sec, fsec);
+ sprintf(str + strlen(str), ":%02d.%06d", tm->tm_sec, fsec);
TrimTrailingZeros(str);
}
#else
- if ((fsec != 0) && (tm->tm_year > 0))
+ if (fsec != 0 && tm->tm_year > 0)
{
- sprintf((str + strlen(str)), ":%09.6f", tm->tm_sec + fsec);
+ sprintf(str + strlen(str), ":%09.6f", tm->tm_sec + fsec);
TrimTrailingZeros(str);
}
#endif
else
- sprintf((str + strlen(str)), ":%02d", tm->tm_sec);
+ sprintf(str + strlen(str), ":%02d", tm->tm_sec);
if (tzp != NULL && tm->tm_isdst >= 0)
{
if (*tzn != NULL)
- sprintf((str + strlen(str)), " %.*s", MAXTZLEN, *tzn);
+ sprintf(str + strlen(str), " %.*s", MAXTZLEN, *tzn);
else
{
hour = -(*tzp / 3600);
- 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);
}
}
if (tm->tm_year <= 0)
- sprintf((str + strlen(str)), " BC");
+ sprintf(str + strlen(str), " BC");
break;
case USE_POSTGRES_DATES:
tm->tm_wday = j2day(day);
strncpy(str, days[tm->tm_wday], 3);
- strcpy((str + 3), " ");
-
+ strcpy(str + 3, " ");
+
if (DateOrder == DATEORDER_DMY)
- 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]);
else
- 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);
- sprintf((str + 10), " %02d:%02d", tm->tm_hour, tm->tm_min);
+ sprintf(str + 10, " %02d:%02d", tm->tm_hour, tm->tm_min);
/*
* Print fractional seconds if any. The field widths here
#ifdef HAVE_INT64_TIMESTAMP
if (fsec != 0)
{
- sprintf((str + strlen(str)), ":%02d.%06d", tm->tm_sec, fsec);
+ sprintf(str + strlen(str), ":%02d.%06d", tm->tm_sec, fsec);
TrimTrailingZeros(str);
}
#else
- if ((fsec != 0) && (tm->tm_year > 0))
+ if (fsec != 0 && tm->tm_year > 0)
{
- sprintf((str + strlen(str)), ":%09.6f", tm->tm_sec + fsec);
+ sprintf(str + strlen(str), ":%09.6f", tm->tm_sec + fsec);
TrimTrailingZeros(str);
}
#endif
else
- sprintf((str + strlen(str)), ":%02d", tm->tm_sec);
+ sprintf(str + strlen(str), ":%02d", tm->tm_sec);
- 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));
if (tzp != NULL && tm->tm_isdst >= 0)
{
if (*tzn != NULL)
- sprintf((str + strlen(str)), " %.*s", MAXTZLEN, *tzn);
+ sprintf(str + strlen(str), " %.*s", MAXTZLEN, *tzn);
else
{
/*
* 2001-10-19
*/
hour = -(*tzp / 3600);
- 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);
}
}
if (tm->tm_year <= 0)
- sprintf((str + strlen(str)), " BC");
+ sprintf(str + strlen(str), " BC");
break;
}
if (tm->tm_year != 0)
{
sprintf(cp, "%d year%s",
- tm->tm_year, ((tm->tm_year != 1) ? "s" : ""));
+ tm->tm_year, (tm->tm_year != 1) ? "s" : "");
cp += strlen(cp);
is_before = (tm->tm_year < 0);
is_nonzero = TRUE;
if (tm->tm_mon != 0)
{
- 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" : "");
cp += strlen(cp);
is_before = (tm->tm_mon < 0);
is_nonzero = TRUE;
if (tm->tm_mday != 0)
{
- 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" : "");
cp += strlen(cp);
is_before = (tm->tm_mday < 0);
is_nonzero = TRUE;
}
- 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)
{
- 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);
- sprintf(cp, "%s%s%02d:%02d", (is_nonzero ? " " : ""),
+ sprintf(cp, "%s%s%02d:%02d", is_nonzero ? " " : "",
(minus ? "-" : (is_before ? "+" : "")),
abs(tm->tm_hour), abs(tm->tm_min));
cp += strlen(cp);
year = -year;
sprintf(cp, "%d year%s", year,
- ((year != 1) ? "s" : ""));
+ (year != 1) ? "s" : "");
cp += strlen(cp);
is_before = (tm->tm_year < 0);
is_nonzero = TRUE;
{
int mon = tm->tm_mon;
- if (is_before || ((!is_nonzero) && (tm->tm_mon < 0)))
+ if (is_before || (!is_nonzero && tm->tm_mon < 0))
mon = -mon;
- sprintf(cp, "%s%d mon%s", (is_nonzero ? " " : ""), mon,
- ((mon != 1) ? "s" : ""));
+ sprintf(cp, "%s%d mon%s", is_nonzero ? " " : "", mon,
+ (mon != 1) ? "s" : "");
cp += strlen(cp);
if (!is_nonzero)
is_before = (tm->tm_mon < 0);
{
int day = tm->tm_mday;
- if (is_before || ((!is_nonzero) && (tm->tm_mday < 0)))
+ if (is_before || (!is_nonzero && tm->tm_mday < 0))
day = -day;
- sprintf(cp, "%s%d day%s", (is_nonzero ? " " : ""), day,
- ((day != 1) ? "s" : ""));
+ sprintf(cp, "%s%d day%s", is_nonzero ? " " : "", day,
+ (day != 1) ? "s" : "");
cp += strlen(cp);
if (!is_nonzero)
is_before = (tm->tm_mday < 0);
{
int hour = tm->tm_hour;
- if (is_before || ((!is_nonzero) && (tm->tm_hour < 0)))
+ if (is_before || (!is_nonzero && tm->tm_hour < 0))
hour = -hour;
- sprintf(cp, "%s%d hour%s", (is_nonzero ? " " : ""), hour,
- ((hour != 1) ? "s" : ""));
+ sprintf(cp, "%s%d hour%s", is_nonzero ? " " : "", hour,
+ (hour != 1) ? "s" : "");
cp += strlen(cp);
if (!is_nonzero)
is_before = (tm->tm_hour < 0);
{
int min = tm->tm_min;
- if (is_before || ((!is_nonzero) && (tm->tm_min < 0)))
+ if (is_before || (!is_nonzero && tm->tm_min < 0))
min = -min;
- sprintf(cp, "%s%d min%s", (is_nonzero ? " " : ""), min,
- ((min != 1) ? "s" : ""));
+ sprintf(cp, "%s%d min%s", is_nonzero ? " " : "", min,
+ (min != 1) ? "s" : "");
cp += strlen(cp);
if (!is_nonzero)
is_before = (tm->tm_min < 0);
#ifdef HAVE_INT64_TIMESTAMP
sec = fsec;
- if (is_before || ((!is_nonzero) && (tm->tm_sec < 0)))
+ if (is_before || (!is_nonzero && tm->tm_sec < 0))
{
tm->tm_sec = -tm->tm_sec;
sec = -sec;
is_before = TRUE;
}
- else if ((!is_nonzero) && (tm->tm_sec == 0) && (fsec < 0))
+ else if (!is_nonzero && tm->tm_sec == 0 && fsec < 0)
{
sec = -sec;
is_before = TRUE;
}
- 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);
cp += strlen(cp);
#else
fsec += tm->tm_sec;
sec = fsec;
- if (is_before || ((!is_nonzero) && (fsec < 0)))
+ if (is_before || (!is_nonzero && fsec < 0))
sec = -sec;
- sprintf(cp, "%s%.2f secs", (is_nonzero ? " " : ""), sec);
+ sprintf(cp, "%s%.2f secs", is_nonzero ? " " : "", sec);
cp += strlen(cp);
if (!is_nonzero)
is_before = (fsec < 0);
{
int sec = tm->tm_sec;
- if (is_before || ((!is_nonzero) && (tm->tm_sec < 0)))
+ if (is_before || (!is_nonzero && tm->tm_sec < 0))
sec = -sec;
- sprintf(cp, "%s%d sec%s", (is_nonzero ? " " : ""), sec,
- ((sec != 1) ? "s" : ""));
+ sprintf(cp, "%s%d sec%s", is_nonzero ? " " : "", sec,
+ (sec != 1) ? "s" : "");
cp += strlen(cp);
if (!is_nonzero)
is_before = (tm->tm_sec < 0);
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.119 2005/04/19 03:13:59 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.120 2005/05/23 17:13:14 momjian Exp $
*
*-------------------------------------------------------------------------
*/
if (!TIMESTAMP_NOT_FINITE(*time)
&& (typmod != -1) && (typmod != MAX_TIMESTAMP_PRECISION))
{
- if ((typmod < 0) || (typmod > MAX_TIMESTAMP_PRECISION))
+ if (typmod < 0 || typmod > MAX_TIMESTAMP_PRECISION)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("timestamp(%d) precision must be between %d and %d",
interval = (Interval *) palloc(sizeof(Interval));
#ifdef HAVE_INT64_TIMESTAMP
- interval ->time = pq_getmsgint64(buf);
+ interval->time = pq_getmsgint64(buf);
#else
- interval ->time = pq_getmsgfloat8(buf);
+ interval->time = pq_getmsgfloat8(buf);
#endif
- interval ->month = pq_getmsgint(buf, sizeof(interval->month));
+ interval->month = pq_getmsgint(buf, sizeof(interval->month));
PG_RETURN_INTERVAL_P(interval);
}
}
else if (range == INTERVAL_MASK(YEAR))
{
- interval ->month = ((interval->month / 12) *12);
- interval ->time = 0;
+ interval->month = (interval->month / 12) * 12;
+ interval->time = 0;
}
else if (range == INTERVAL_MASK(MONTH))
{
- interval ->month %= 12;
- interval ->time = 0;
+ interval->month %= 12;
+ interval->time = 0;
}
/* YEAR TO MONTH */
else if (range == (INTERVAL_MASK(YEAR) | INTERVAL_MASK(MONTH)))
- interval ->time = 0;
+ interval->time = 0;
else if (range == INTERVAL_MASK(DAY))
{
- interval ->month = 0;
+ interval->month = 0;
#ifdef HAVE_INT64_TIMESTAMP
- interval ->time = (((int) (interval->time / INT64CONST(86400000000)))
- * INT64CONST(86400000000));
+ interval->time = ((int) (interval->time / INT64CONST(86400000000))) *
+ INT64CONST(86400000000);
#else
- interval ->time = (((int) (interval->time / 86400)) * 86400);
+ interval->time = ((int) (interval->time / 86400)) * 86400;
#endif
}
else if (range == INTERVAL_MASK(HOUR))
double day;
#endif
- interval ->month = 0;
+ interval->month = 0;
#ifdef HAVE_INT64_TIMESTAMP
- 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);
#else
TMODULO(interval->time, day, 86400.0);
- interval ->time = (((int) (interval->time / 3600)) * 3600.0);
+ interval->time = ((int) (interval->time / 3600)) * 3600.0;
#endif
}
else if (range == INTERVAL_MASK(MINUTE))
double hour;
#endif
- interval ->month = 0;
+ interval->month = 0;
#ifdef HAVE_INT64_TIMESTAMP
- 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);
#else
TMODULO(interval->time, hour, 3600.0);
- interval ->time = (((int) (interval->time / 60)) * 60);
+ interval->time = ((int) (interval->time / 60)) * 60;
#endif
}
else if (range == INTERVAL_MASK(SECOND))
double minute;
#endif
- interval ->month = 0;
+ interval->month = 0;
#ifdef HAVE_INT64_TIMESTAMP
- minute = (interval->time / INT64CONST(60000000));
- interval ->time -= (minute * INT64CONST(60000000));
+ minute = interval->time / INT64CONST(60000000);
+ interval->time -= minute * INT64CONST(60000000);
#else
TMODULO(interval->time, minute, 60.0);
else if (range == (INTERVAL_MASK(DAY) |
INTERVAL_MASK(HOUR)))
{
- interval ->month = 0;
+ interval->month = 0;
#ifdef HAVE_INT64_TIMESTAMP
- interval ->time = ((interval->time / INT64CONST(3600000000))
- *INT64CONST(3600000000));
+ interval->time = (interval->time / INT64CONST(3600000000)) *
+ INT64CONST(3600000000);
#else
- interval ->time = (((int) (interval->time / 3600)) * 3600);
+ interval->time = ((int) (interval->time / 3600)) * 3600;
#endif
}
/* DAY TO MINUTE */
INTERVAL_MASK(HOUR) |
INTERVAL_MASK(MINUTE)))
{
- interval ->month = 0;
+ interval->month = 0;
#ifdef HAVE_INT64_TIMESTAMP
- interval ->time = ((interval->time / INT64CONST(60000000))
- *INT64CONST(60000000));
+ interval->time = (interval->time / INT64CONST(60000000)) *
+ INT64CONST(60000000);
#else
- interval ->time = (((int) (interval->time / 60)) * 60);
+ interval->time = ((int) (interval->time / 60)) * 60;
#endif
}
/* DAY TO SECOND */
INTERVAL_MASK(HOUR) |
INTERVAL_MASK(MINUTE) |
INTERVAL_MASK(SECOND)))
- interval ->month = 0;
+ interval->month = 0;
/* HOUR TO MINUTE */
else if (range == (INTERVAL_MASK(HOUR) |
double day;
#endif
- interval ->month = 0;
+ interval->month = 0;
#ifdef HAVE_INT64_TIMESTAMP
day = (interval->time / INT64CONST(86400000000));
- 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);
#else
TMODULO(interval->time, day, 86400.0);
- interval ->time = (((int) (interval->time / 60)) * 60);
+ interval->time = ((int) (interval->time / 60)) * 60;
#endif
}
/* HOUR TO SECOND */
double day;
#endif
- interval ->month = 0;
+ interval->month = 0;
#ifdef HAVE_INT64_TIMESTAMP
- day = (interval->time / INT64CONST(86400000000));
- interval ->time -= (day * INT64CONST(86400000000));
+ day = interval->time / INT64CONST(86400000000);
+ interval->time -= day * INT64CONST(86400000000);
#else
TMODULO(interval->time, day, 86400.0);
double hour;
#endif
- interval ->month = 0;
+ interval->month = 0;
#ifdef HAVE_INT64_TIMESTAMP
- hour = (interval->time / INT64CONST(3600000000));
- interval ->time -= (hour * INT64CONST(3600000000));
-
+ hour = interval->time / INT64CONST(3600000000);
+ interval->time -= hour * INT64CONST(3600000000);
#else
TMODULO(interval->time, hour, 3600.0);
#endif
/* Need to adjust precision? If not, don't even try! */
if (precision != INTERVAL_FULL_PRECISION)
{
- if ((precision < 0) || (precision > MAX_INTERVAL_PRECISION))
+ if (precision < 0 || precision > MAX_INTERVAL_PRECISION)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("interval(%d) precision must be between %d and %d",
#ifdef HAVE_INT64_TIMESTAMP
if (interval->time >= INT64CONST(0))
{
- interval ->time = (((interval->time + IntervalOffsets[precision]) /IntervalScales[precision])
- * IntervalScales[precision]);
+ interval->time = (((interval->time +
+ IntervalOffsets[precision]) /
+ IntervalScales[precision]) *
+ IntervalScales[precision];
}
else
{
- interval ->time = -(((-interval->time + IntervalOffsets[precision]) /IntervalScales[precision])
- * IntervalScales[precision]);
+ interval->time = -(((-interval->time +
+ IntervalOffsets[precision]) /
+ IntervalScales[precision]) *
+ IntervalScales[precision]);
}
#else
- interval ->time = (rint(((double) interval->time) *IntervalScales[precision])
- / IntervalScales[precision]);
+ interval->time = rint(((double) interval->time) *
+ IntervalScales[precision]) /
+ IntervalScales[precision];
#endif
}
}
time = jd;
#ifdef HAVE_INT64_TIMESTAMP
- *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)));
+ *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 / 3600;
+ time -= (*hour) * 3600;
+ *min = time / 60;
+ time -= (*min) * 60;
*sec = time;
*fsec = JROUND(time - *sec);
#endif
if (time < INT64CONST(0))
{
time += INT64CONST(86400000000);
- date -=1;
+ date -= 1;
}
#else
TMODULO(time, date, 86400e0);
if (time < 0)
{
time += 86400;
- date -=1;
+ date -=1;
}
#endif
time = time2t(tm->tm_hour, tm->tm_min, tm->tm_sec, fsec);
#ifdef HAVE_INT64_TIMESTAMP
- *result = (date *INT64CONST(86400000000)) +time;
+ *result = date * INT64CONST(86400000000) + time;
/* check for major overflow */
if ((*result - time) / INT64CONST(86400000000) != date)
return -1;
/* check for just-barely overflow (okay except time-of-day wraps) */
- if ((*result < 0) ? (date >=0) : (date <0))
+ if ((*result < 0 && date >= 0) ||
+ (*result >= 0 && date < 0))
return -1;
#else
- *result = ((date *86400) +time);
+ *result = date * 86400 + time;
#endif
if (tzp != NULL)
*result = dt2local(*result, -(*tzp));
int
tm2interval(struct pg_tm * tm, fsec_t fsec, Interval *span)
{
- span->month = ((tm->tm_year * 12) + tm->tm_mon);
+ span->month = tm->tm_year * 12 + tm->tm_mon;
#ifdef HAVE_INT64_TIMESTAMP
span->time = ((((((((tm->tm_mday * INT64CONST(24))
+ tm->tm_hour) * INT64CONST(60))
#ifdef HAVE_INT64_TIMESTAMP
if (interval1->month != 0)
- span1 += ((interval1->month * INT64CONST(30) * INT64CONST(86400000000)));
+ span1 += interval1->month * INT64CONST(30) * INT64CONST(86400000000);
if (interval2->month != 0)
- span2 += ((interval2->month * INT64CONST(30) * INT64CONST(86400000000)));
+ span2 += interval2->month * INT64CONST(30) * INT64CONST(86400000000);
#else
if (interval1->month != 0)
- span1 += (interval1->month * (30.0 * 86400));
+ span1 += interval1->month * (30.0 * 86400);
if (interval2->month != 0)
- span2 += (interval2->month * (30.0 * 86400));
+ span2 += interval2->month * (30.0 * 86400);
#endif
return ((span1 < span2) ? -1 : (span1 > span2) ? 1 : 0);
#ifdef HAVE_INT64_TIMESTAMP
result->month = months;
result->time = (span1->time * factor);
- result->time += ((months - result->month) * INT64CONST(30)
- * INT64CONST(86400000000));
+ result->time += (months - result->month) * INT64CONST(30) *
+ INT64CONST(86400000000);
#else
result->month = rint(months);
result->time = JROUND(span1->time * factor);
result->month = (span->month / factor);
result->time = (span->time / factor);
/* evaluate fractional months as 30 days */
- result->time += (((span->month - (result->month * factor))
- * INT64CONST(30) * INT64CONST(86400000000)) / factor);
+ result->time += ((span->month - (result->month * factor)) *
+ INT64CONST(30) * INT64CONST(86400000000)) / factor;
#else
- months = (span->month / factor);
+ months = span->month / factor;
result->month = rint(months);
result->time = JROUND(span->time / factor);
/* evaluate fractional months as 30 days */
result = (Interval *) palloc(sizeof(Interval));
- 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)
{
fsec = (fsec1 - fsec2);
tm->tm_sec = (tm1->tm_sec - tm2->tm_sec);
result = (Interval *) palloc(sizeof(Interval));
- 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)
{
fsec = (fsec1 - fsec2);
tm->tm_sec = (tm1->tm_sec - tm2->tm_sec);
case DTK_MILLISEC:
#ifdef HAVE_INT64_TIMESTAMP
- fsec = ((fsec / 1000) * 1000);
+ fsec = (fsec / 1000) * 1000;
#else
fsec = rint(fsec * 1000) / 1000;
#endif
* We need the first week containing a Thursday, otherwise this day
* falls into the previous year for purposes of counting weeks
*/
- if (dayn < (day4 - day0))
+ if (dayn < day4 - day0)
{
day4 = date2j(year - 1, 1, 4);
day0 = j2day(day4 - 1);
}
- result = (((dayn - (day4 - day0)) / 7) + 1);
+ result = (dayn - (day4 - day0)) / 7 + 1;
/*
* Sometimes the last few days in a year will fall into the first week
/* day0 == offset to first day of week (Monday) */
day0 = j2day(day4 - 1);
- if (dayn >= (day4 - day0))
- result = (((dayn - (day4 - day0)) / 7) + 1);
+ if (dayn >= day4 - day0)
+ result = (dayn - (day4 - day0)) / 7 + 1;
}
return (int) result;
* We need the first week containing a Thursday, otherwise this day
* falls into the previous year for purposes of counting weeks
*/
- if (dayn < (day4 - day0))
+ if (dayn < day4 - day0)
{
day4 = date2j(year - 1, 1, 4);
year--;
}
- result = (((dayn - (day4 - day0)) / 7) + 1);
+ result = (dayn - (day4 - day0)) / 7 + 1;
/*
* Sometimes the last few days in a year will fall into the first week
/* day0 == offset to first day of week (Monday) */
day0 = j2day(day4 - 1);
- if (dayn >= (day4 - day0))
+ if (dayn >= day4 - day0)
year++;
}
{
case DTK_MICROSEC:
#ifdef HAVE_INT64_TIMESTAMP
- result = ((tm->tm_sec * 1000000e0) + fsec);
+ result = tm->tm_sec * 1000000e0 + fsec;
#else
result = (tm->tm_sec + fsec) * 1000000;
#endif
case DTK_MILLISEC:
#ifdef HAVE_INT64_TIMESTAMP
- result = ((tm->tm_sec * 1000e0) + (fsec / 1000e0));
+ result = tm->tm_sec * 1000e0 + fsec / 1000e0;
#else
result = (tm->tm_sec + fsec) * 1000;
#endif
case DTK_SECOND:
#ifdef HAVE_INT64_TIMESTAMP
- result = (tm->tm_sec + (fsec / 1000000e0));
+ result = tm->tm_sec + fsec / 1000000e0;
#else
- result = (tm->tm_sec + fsec);
+ result = tm->tm_sec + fsec;
#endif
break;
break;
case DTK_QUARTER:
- result = ((tm->tm_mon - 1) / 3) + 1;
+ result = (tm->tm_mon - 1) / 3 + 1;
break;
case DTK_WEEK:
case DTK_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.
+ /* ----
+ * 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.
+ * ----
*/
if (tm->tm_year > 0)
result = ((tm->tm_year + 99) / 100);
case DTK_JULIAN:
result = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday);
#ifdef HAVE_INT64_TIMESTAMP
- 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;
#else
- 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;
#endif
break;
case DTK_MICROSEC:
#ifdef HAVE_INT64_TIMESTAMP
- result = ((tm->tm_sec * 1000000e0) + fsec);
+ result = tm->tm_sec * 1000000e0 + fsec;
#else
result = (tm->tm_sec + fsec) * 1000000;
#endif
case DTK_MILLISEC:
#ifdef HAVE_INT64_TIMESTAMP
- result = ((tm->tm_sec * 1000e0) + (fsec / 1000e0));
+ result = tm->tm_sec * 1000e0 + fsec / 1000e0;
#else
result = (tm->tm_sec + fsec) * 1000;
#endif
case DTK_SECOND:
#ifdef HAVE_INT64_TIMESTAMP
- result = (tm->tm_sec + (fsec / 1000000e0));
+ result = tm->tm_sec + fsec / 1000000e0;
#else
- result = (tm->tm_sec + fsec);
+ result = tm->tm_sec + fsec;
#endif
break;
break;
case DTK_QUARTER:
- result = ((tm->tm_mon - 1) / 3) + 1;
+ result = (tm->tm_mon - 1) / 3 + 1;
break;
case DTK_WEEK:
case DTK_CENTURY:
/* see comments in timestamp_part */
if (tm->tm_year > 0)
- result = ((tm->tm_year + 99) / 100);
+ result = (tm->tm_year + 99) / 100;
else
result = -((99 - (tm->tm_year - 1)) / 100);
break;
case DTK_MILLENNIUM:
/* see comments in timestamp_part */
if (tm->tm_year > 0)
- result = ((tm->tm_year + 999) / 1000);
+ result = (tm->tm_year + 999) / 1000;
else
result = -((999 - (tm->tm_year - 1)) / 1000);
break;
case DTK_JULIAN:
result = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday);
#ifdef HAVE_INT64_TIMESTAMP
- 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;
#else
- 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;
#endif
break;
{
case DTK_EPOCH:
#ifdef HAVE_INT64_TIMESTAMP
- result = ((timestamp -SetEpochTimestamp()) /1000000e0);
+ result = (timestamp - SetEpochTimestamp()) /1000000e0;
#else
- result = timestamp -SetEpochTimestamp();
+ result = timestamp - SetEpochTimestamp();
#endif
break;
{
case DTK_MICROSEC:
#ifdef HAVE_INT64_TIMESTAMP
- result = ((tm->tm_sec * 1000000e0) + fsec);
+ result = tm->tm_sec * 1000000e0 + fsec;
#else
result = (tm->tm_sec + fsec) * 1000000;
#endif
case DTK_MILLISEC:
#ifdef HAVE_INT64_TIMESTAMP
- result = ((tm->tm_sec * 1000e0) + (fsec / 1000e0));
+ result = tm->tm_sec * 1000e0 + fsec / 1000e0;
#else
result = (tm->tm_sec + fsec) * 1000;
#endif
case DTK_SECOND:
#ifdef HAVE_INT64_TIMESTAMP
- result = (tm->tm_sec + (fsec / 1000000e0));
+ result = tm->tm_sec + fsec / 1000000e0;
#else
- result = (tm->tm_sec + fsec);
+ result = tm->tm_sec + fsec;
#endif
break;
result = 0;
}
}
- else if ((type == RESERV) && (val == DTK_EPOCH))
+ else if (type == RESERV && val == DTK_EPOCH)
{
#ifdef HAVE_INT64_TIMESTAMP
- result = (interval->time / 1000000e0);
+ result = interval->time / 1000000e0;
#else
result = interval->time;
#endif
if (interval->month != 0)
{
- 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);
}
}
else
type = DecodeSpecial(0, lowzone, &val);
- if ((type == TZ) || (type == DTZ))
+ if (type == TZ || type == DTZ)
{
tz = -(val * 60);
PointerGetDatum(zone))))));
#ifdef HAVE_INT64_TIMESTAMP
- tz = (zone->time / INT64CONST(1000000));
+ tz = zone->time / INT64CONST(1000000);
#else
- tz = (zone->time);
+ tz = zone->time;
#endif
result = dt2local(timestamp, tz);
type = DecodeSpecial(0, lowzone, &val);
- if ((type == TZ) || (type == DTZ))
+ if (type == TZ || type == DTZ)
{
tz = val * 60;