*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/date.c,v 1.107 2005/05/23 21:54:01 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/date.c,v 1.108 2005/05/24 02:09:45 momjian Exp $
*
*-------------------------------------------------------------------------
*/
tm2time(struct pg_tm * tm, fsec_t fsec, TimeADT *result)
{
#ifdef HAVE_INT64_TIMESTAMP
- *result = ((((((tm->tm_hour * 60) + tm->tm_min) * 60) + tm->tm_sec)
- * USECS_PER_SEC) + fsec);
+ *result = ((((tm->tm_hour * 60 + tm->tm_min) * 60) + tm->tm_sec)
+ * USECS_PER_SEC) + fsec;
#else
- *result = ((((tm->tm_hour * 60) + tm->tm_min) * 60) + tm->tm_sec + fsec);
+ *result = ((tm->tm_hour * 60 + tm->tm_min) * 60) + tm->tm_sec + fsec;
#endif
return 0;
}
time2tm(TimeADT time, struct pg_tm * tm, fsec_t *fsec)
{
#ifdef HAVE_INT64_TIMESTAMP
- tm->tm_hour = (time / USECS_PER_HOUR);
- time -= (tm->tm_hour * USECS_PER_HOUR);
- tm->tm_min = (time / USECS_PER_MINUTE);
- time -= (tm->tm_min * USECS_PER_MINUTE);
- tm->tm_sec = (time / USECS_PER_SEC);
- time -= (tm->tm_sec * USECS_PER_SEC);
+ tm->tm_hour = time / USECS_PER_HOUR;
+ time -= tm->tm_hour * USECS_PER_HOUR;
+ tm->tm_min = time / USECS_PER_MINUTE;
+ time -= tm->tm_min * USECS_PER_MINUTE;
+ tm->tm_sec = time / USECS_PER_SEC;
+ time -= tm->tm_sec * USECS_PER_SEC;
*fsec = time;
#else
double trem;
};
#endif
- if ((typmod >= 0) && (typmod <= MAX_TIME_PRECISION))
+ if (typmod >= 0 && typmod <= MAX_TIME_PRECISION)
{
/*
* Note: this round-to-nearest code is not completely consistent
#ifdef HAVE_INT64_TIMESTAMP
if (*time >= INT64CONST(0))
{
- *time = (((*time + TimeOffsets[typmod]) / TimeScales[typmod])
- * TimeScales[typmod]);
+ *time = ((*time + TimeOffsets[typmod]) / TimeScales[typmod]) *
+ TimeScales[typmod];
}
else
{
- *time = -((((-*time) + TimeOffsets[typmod]) / TimeScales[typmod])
- * TimeScales[typmod]);
+ *time = -((((-*time) + TimeOffsets[typmod]) / TimeScales[typmod]) *
+ TimeScales[typmod]);
}
#else
- *time = (rint(((double) *time) * TimeScales[typmod])
- / TimeScales[typmod]);
+ *time = rint((double)*time * TimeScales[typmod])
+ / TimeScales[typmod];
#endif
}
}
* Could also do this with time = (timestamp / USECS_PER_DAY *
* USECS_PER_DAY) - timestamp;
*/
- result = ((((((tm->tm_hour * 60) + tm->tm_min) * 60) + tm->tm_sec)
- * USECS_PER_SEC) + fsec);
+ result = ((((tm->tm_hour * 60 + tm->tm_min) * 60) + tm->tm_sec) *
+ USECS_PER_SEC) + fsec;
#else
- result = ((((tm->tm_hour * 60) + tm->tm_min) * 60) + tm->tm_sec + fsec);
+ result = ((tm->tm_hour * 60 + tm->tm_min) * 60) + tm->tm_sec + fsec;
#endif
PG_RETURN_TIMEADT(result);
* Could also do this with time = (timestamp / USECS_PER_DAY *
* USECS_PER_DAY) - timestamp;
*/
- result = ((((((tm->tm_hour * 60) + tm->tm_min) * 60) + tm->tm_sec)
- * USECS_PER_SEC) + fsec);
+ result = ((((tm->tm_hour * 60 + tm->tm_min) * 60) + tm->tm_sec) *
+ USECS_PER_SEC) + fsec;
#else
- result = ((((tm->tm_hour * 60) + tm->tm_min) * 60) + tm->tm_sec + fsec);
+ result = ((tm->tm_hour * 60 + tm->tm_min) * 60) + tm->tm_sec + fsec;
#endif
PG_RETURN_TIMEADT(result);
{
case DTK_MICROSEC:
#ifdef HAVE_INT64_TIMESTAMP
- result = ((tm->tm_sec * USECS_PER_SEC) + fsec);
+ result = tm->tm_sec * USECS_PER_SEC + fsec;
#else
- result = ((tm->tm_sec + fsec) * 1000000);
+ result = (tm->tm_sec + fsec) * 1000000;
#endif
break;
case DTK_MILLISEC:
#ifdef HAVE_INT64_TIMESTAMP
- result = ((tm->tm_sec * INT64CONST(1000))
- + (fsec / INT64CONST(1000)));
+ result = tm->tm_sec * INT64CONST(1000) + fsec / INT64CONST(1000);
#else
- result = ((tm->tm_sec + fsec) * 1000);
+ result = (tm->tm_sec + fsec) * 1000;
#endif
break;
case DTK_SECOND:
#ifdef HAVE_INT64_TIMESTAMP
- result = (tm->tm_sec + (fsec / USECS_PER_SEC));
+ result = tm->tm_sec + fsec / USECS_PER_SEC;
#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 = (time / 1000000e0);
tm2timetz(struct pg_tm * tm, fsec_t fsec, int tz, TimeTzADT *result)
{
#ifdef HAVE_INT64_TIMESTAMP
- result->time = ((((((tm->tm_hour * 60) + tm->tm_min) * 60) + tm->tm_sec)
- * USECS_PER_SEC) + fsec);
+ result->time = ((((tm->tm_hour * 60 + tm->tm_min) * 60) + tm->tm_sec) *
+ USECS_PER_SEC) + fsec;
#else
- result->time = ((((tm->tm_hour * 60) + tm->tm_min) * 60) + tm->tm_sec + fsec);
+ result->time = ((tm->tm_hour * 60 + tm->tm_min) * 60) + tm->tm_sec + fsec;
#endif
result->zone = tz;
#ifdef HAVE_INT64_TIMESTAMP
int64 trem = time->time;
- tm->tm_hour = (trem / USECS_PER_HOUR);
- trem -= (tm->tm_hour * USECS_PER_HOUR);
- tm->tm_min = (trem / USECS_PER_MINUTE);
- trem -= (tm->tm_min * USECS_PER_MINUTE);
- tm->tm_sec = (trem / USECS_PER_SEC);
- *fsec = (trem - (tm->tm_sec * USECS_PER_SEC));
+ tm->tm_hour = trem / USECS_PER_HOUR;
+ trem -= tm->tm_hour * USECS_PER_HOUR;
+ tm->tm_min = trem / USECS_PER_MINUTE;
+ trem -= tm->tm_min * USECS_PER_MINUTE;
+ tm->tm_sec = trem / USECS_PER_SEC;
+ *fsec = trem - tm->tm_sec * USECS_PER_SEC;
#else
double trem = time->time;
TimestampTz result;
#ifdef HAVE_INT64_TIMESTAMP
- result = (((date *USECS_PER_DAY) +time->time)
- + (time->zone * USECS_PER_SEC));
+ result = (date * USECS_PER_DAY + time->time) + time->zone * USECS_PER_SEC;
#else
- result = (((date *(double)SECS_PER_DAY) +time->time) + time->zone);
+ result = date * (double)SECS_PER_DAY + time->time + time->zone;
#endif
PG_RETURN_TIMESTAMP(result);
case DTK_MICROSEC:
#ifdef HAVE_INT64_TIMESTAMP
- result = ((tm->tm_sec * USECS_PER_SEC) + fsec);
+ result = tm->tm_sec * USECS_PER_SEC + fsec;
#else
- result = ((tm->tm_sec + fsec) * 1000000);
+ result = (tm->tm_sec + fsec) * 1000000;
#endif
break;
case DTK_MILLISEC:
#ifdef HAVE_INT64_TIMESTAMP
- result = ((tm->tm_sec * INT64CONST(1000))
- + (fsec / INT64CONST(1000)));
+ result = tm->tm_sec * INT64CONST(1000) + fsec / INT64CONST(1000);
#else
- result = ((tm->tm_sec + fsec) * 1000);
+ result = (tm->tm_sec + fsec) * 1000;
#endif
break;
case DTK_SECOND:
#ifdef HAVE_INT64_TIMESTAMP
- result = (tm->tm_sec + (fsec / USECS_PER_SEC));
+ result = tm->tm_sec + fsec / USECS_PER_SEC;
#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 = ((time->time / 1000000e0) + time->zone);
+ result = time->time / 1000000e0 + time->zone;
#else
- result = (time->time + time->zone);
+ result = time->time + time->zone;
#endif
}
else
result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
- if ((type == TZ) || (type == DTZ))
+ if (type == TZ || type == DTZ)
{
tz = val * 60;
#ifdef HAVE_INT64_TIMESTAMP
- result->time = time->time + ((time->zone - tz) * USECS_PER_SEC);
+ result->time = time->time + (time->zone - tz) * USECS_PER_SEC;
while (result->time < INT64CONST(0))
result->time += USECS_PER_DAY;
while (result->time >= USECS_PER_DAY)
result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
#ifdef HAVE_INT64_TIMESTAMP
- result->time = time->time + ((time->zone - tz) * USECS_PER_SEC);
+ result->time = time->time + (time->zone - tz) * USECS_PER_SEC;
while (result->time < INT64CONST(0))
result->time += USECS_PER_DAY;
while (result->time >= USECS_PER_DAY)
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.143 2005/05/23 21:54:01 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.144 2005/05/24 02:09:45 momjian Exp $
*
*-------------------------------------------------------------------------
*/
return DTERR_BAD_FORMAT;
if (*field[i] == '-')
- fval = -(fval);
+ fval = -fval;
}
else if (*cp == '\0')
fval = 0;
{
case DTK_MICROSEC:
#ifdef HAVE_INT64_TIMESTAMP
- *fsec += (val + fval);
+ *fsec += val + fval;
#else
- *fsec += ((val + fval) * 1e-6);
+ *fsec += (val + fval) * 1e-6;
#endif
break;
case DTK_MILLISEC:
#ifdef HAVE_INT64_TIMESTAMP
- *fsec += ((val + fval) * 1000);
+ *fsec += (val + fval) * 1000;
#else
- *fsec += ((val + fval) * 1e-3);
+ *fsec += (val + fval) * 1e-3;
#endif
break;
case DTK_SECOND:
tm->tm_sec += val;
#ifdef HAVE_INT64_TIMESTAMP
- *fsec += (fval * 1000000);
+ *fsec += fval * 1000000;
#else
*fsec += fval;
#endif
sec = fval;
tm->tm_sec += sec;
#ifdef HAVE_INT64_TIMESTAMP
- *fsec += ((fval - sec) * 1000000);
+ *fsec += (fval - sec) * 1000000;
#else
- *fsec += (fval - sec);
+ *fsec += fval - sec;
#endif
}
tmask = DTK_M(MINUTE);
sec = fval;
tm->tm_sec += sec;
#ifdef HAVE_INT64_TIMESTAMP
- *fsec += ((fval - sec) * 1000000);
+ *fsec += (fval - sec) * 1000000;
#else
- *fsec += (fval - sec);
+ *fsec += fval - sec;
#endif
}
tmask = DTK_M(HOUR);
sec = fval;
tm->tm_sec += sec;
#ifdef HAVE_INT64_TIMESTAMP
- *fsec += ((fval - sec) * 1000000);
+ *fsec += (fval - sec) * 1000000;
#else
- *fsec += (fval - sec);
+ *fsec += fval - sec;
#endif
}
tmask = (fmask & DTK_M(DAY)) ? 0 : DTK_M(DAY);
{
int sec;
- fval *= (7 * SECS_PER_DAY);
+ fval *= 7 * SECS_PER_DAY;
sec = fval;
tm->tm_sec += sec;
#ifdef HAVE_INT64_TIMESTAMP
- *fsec += ((fval - sec) * 1000000);
+ *fsec += (fval - sec) * 1000000;
#else
- *fsec += (fval - sec);
+ *fsec += fval - sec;
#endif
}
tmask = (fmask & DTK_M(DAY)) ? 0 : DTK_M(DAY);
{
int sec;
- fval *= (30 * SECS_PER_DAY);
+ fval *= 30 * SECS_PER_DAY;
sec = fval;
tm->tm_sec += sec;
#ifdef HAVE_INT64_TIMESTAMP
- *fsec += ((fval - sec) * 1000000);
+ *fsec += (fval - sec) * 1000000;
#else
- *fsec += (fval - sec);
+ *fsec += fval - sec;
#endif
}
tmask = DTK_M(MONTH);
case DTK_YEAR:
tm->tm_year += val;
if (fval != 0)
- tm->tm_mon += (fval * 12);
+ tm->tm_mon += fval * 12;
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);
+ tm->tm_mon += fval * 120;
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);
+ tm->tm_mon += fval * 1200;
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);
+ tm->tm_mon += fval * 12000;
tmask = (fmask & DTK_M(YEAR)) ? 0 : DTK_M(YEAR);
break;
if (is_before)
{
*fsec = -(*fsec);
- tm->tm_sec = -(tm->tm_sec);
- tm->tm_min = -(tm->tm_min);
- tm->tm_hour = -(tm->tm_hour);
- tm->tm_mday = -(tm->tm_mday);
- tm->tm_mon = -(tm->tm_mon);
- tm->tm_year = -(tm->tm_year);
+ tm->tm_sec = -tm->tm_sec;
+ tm->tm_min = -tm->tm_min;
+ tm->tm_hour = -tm->tm_hour;
+ tm->tm_mday = -tm->tm_mday;
+ tm->tm_mon = -tm->tm_mon;
+ tm->tm_year = -tm->tm_year;
}
/* ensure that at least one time field has been found */
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/nabstime.c,v 1.130 2005/05/23 21:54:02 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/nabstime.c,v 1.131 2005/05/24 02:09:45 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#include "miscadmin.h"
#include "pgtime.h"
#include "utils/builtins.h"
-
+#include "utils/timestamp.h"
#define MIN_DAYNUM -24856 /* December 13, 1901 */
#define MAX_DAYNUM 24854 /* January 18, 2038 */
if (HasCTZSet && (tzp != NULL))
time -= CTimeZone;
- if ((!HasCTZSet) && (tzp != NULL))
+ if (!HasCTZSet && tzp != NULL)
tx = pg_localtime(&time,global_timezone);
else
tx = pg_gmtime(&time);
day = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) - UNIX_EPOCH_JDATE;
/* check for time out of range */
- if ((day < MIN_DAYNUM) || (day > MAX_DAYNUM))
+ if (day < MIN_DAYNUM || day > MAX_DAYNUM)
return INVALID_ABSTIME;
/* convert to seconds */
{
AbsoluteTime abstime = PG_GETARG_ABSOLUTETIME(0);
- PG_RETURN_BOOL((abstime != INVALID_ABSTIME) &&
- (abstime != NOSTART_ABSTIME) &&
- (abstime != NOEND_ABSTIME));
+ PG_RETURN_BOOL(abstime != INVALID_ABSTIME &&
+ abstime != NOSTART_ABSTIME &&
+ abstime != NOEND_ABSTIME);
}
switch (dtype)
{
case DTK_DELTA:
- result = ((((tm->tm_hour * 60) + tm->tm_min) * 60) + tm->tm_sec);
- result += ((tm->tm_year * 36525 * 864) + (((tm->tm_mon * 30) + tm->tm_mday) * SECS_PER_DAY));
+ result = ((tm->tm_hour * 60 + tm->tm_min) * 60) + tm->tm_sec;
+ result += tm->tm_year * 36525 * 864 + ((tm->tm_mon * 30) + tm->tm_mday) * SECS_PER_DAY;
break;
default:
}
#ifdef HAVE_INT64_TIMESTAMP
- span = ((((INT64CONST(365250000) * year) + (INT64CONST(30000000) * month))
- * INT64CONST(SECS_PER_DAY)) + interval->time);
+ span = ((INT64CONST(365250000) * year + INT64CONST(30000000) * month) *
+ INT64CONST(86400)) + interval->time;
span /= USECS_PER_SEC;
#else
- span = (((((double) 365.25 * year) + ((double) 30 * month)) * SECS_PER_DAY) + interval->time);
+ span = (365.25 * year + 30.0 * month) * SECS_PER_DAY + interval->time;
#endif
- if ((span < INT_MIN) || (span > INT_MAX))
+ if (span < INT_MIN || span > INT_MAX)
time = INVALID_RELTIME;
else
time = span;
result->time = (reltime * USECS_PER_SEC);
#else
- TMODULO(reltime, year, (36525 * 864));
- TMODULO(reltime, month, (30 * SECS_PER_DAY));
+ TMODULO(reltime, year, 36525 * 864);
+ TMODULO(reltime, month, 30 * SECS_PER_DAY);
result->time = reltime;
#endif
- result->month = ((12 * year) + month);
+ result->month = 12 * year + month;
break;
}
if (AbsoluteTimeIsReal(t1) &&
RelativeTimeIsValid(t2) &&
- ((t2 > 0) ? (t1 < NOEND_ABSTIME - t2)
- : (t1 > NOSTART_ABSTIME - t2))) /* prevent overflow */
+ ((t2 > 0 && t1 < NOEND_ABSTIME - t2) ||
+ (t2 <= 0 && t1 > NOSTART_ABSTIME - t2))) /* prevent overflow */
PG_RETURN_ABSOLUTETIME(t1 + t2);
PG_RETURN_ABSOLUTETIME(INVALID_ABSTIME);
if (AbsoluteTimeIsReal(t1) &&
RelativeTimeIsValid(t2) &&
- ((t2 > 0) ? (t1 > NOSTART_ABSTIME + t2)
- : (t1 < NOEND_ABSTIME + t2))) /* prevent overflow */
+ ((t2 > 0 && t1 > NOSTART_ABSTIME + t2) ||
+ (t2 <= 0 && t1 < NOEND_ABSTIME + t2))) /* prevent overflow */
PG_RETURN_ABSOLUTETIME(t1 - t2);
PG_RETURN_ABSOLUTETIME(INVALID_ABSTIME);
* non-INVALID. This is somewhat arbitrary; the important thing is to
* have a consistent sort order.
*/
- a_invalid = ((a->status == T_INTERVAL_INVAL) ||
- (a->data[0] == INVALID_ABSTIME) ||
- (a->data[1] == INVALID_ABSTIME));
- b_invalid = ((b->status == T_INTERVAL_INVAL) ||
- (b->data[0] == INVALID_ABSTIME) ||
- (b->data[1] == INVALID_ABSTIME));
+ a_invalid = a->status == T_INTERVAL_INVAL ||
+ a->data[0] == INVALID_ABSTIME ||
+ a->data[1] == INVALID_ABSTIME;
+ b_invalid = b->status == T_INTERVAL_INVAL ||
+ b->data[0] == INVALID_ABSTIME ||
+ b->data[1] == INVALID_ABSTIME;
if (a_invalid)
{
PG_RETURN_BOOL(false);
rt = DatumGetRelativeTime(DirectFunctionCall1(tintervalrel,
TimeIntervalGetDatum(i)));
- PG_RETURN_BOOL((rt != INVALID_RELTIME) && (rt == t));
+ PG_RETURN_BOOL(rt != INVALID_RELTIME && rt == t);
}
Datum
PG_RETURN_BOOL(false);
rt = DatumGetRelativeTime(DirectFunctionCall1(tintervalrel,
TimeIntervalGetDatum(i)));
- PG_RETURN_BOOL((rt != INVALID_RELTIME) && (rt != t));
+ PG_RETURN_BOOL(rt != INVALID_RELTIME && rt != t);
}
Datum
PG_RETURN_BOOL(false);
rt = DatumGetRelativeTime(DirectFunctionCall1(tintervalrel,
TimeIntervalGetDatum(i)));
- PG_RETURN_BOOL((rt != INVALID_RELTIME) && (rt < t));
+ PG_RETURN_BOOL(rt != INVALID_RELTIME && rt < t);
}
Datum
PG_RETURN_BOOL(false);
rt = DatumGetRelativeTime(DirectFunctionCall1(tintervalrel,
TimeIntervalGetDatum(i)));
- PG_RETURN_BOOL((rt != INVALID_RELTIME) && (rt > t));
+ PG_RETURN_BOOL(rt != INVALID_RELTIME && rt > t);
}
Datum
PG_RETURN_BOOL(false);
rt = DatumGetRelativeTime(DirectFunctionCall1(tintervalrel,
TimeIntervalGetDatum(i)));
- PG_RETURN_BOOL((rt != INVALID_RELTIME) && (rt <= t));
+ PG_RETURN_BOOL(rt != INVALID_RELTIME && rt <= t);
}
Datum
PG_RETURN_BOOL(false);
rt = DatumGetRelativeTime(DirectFunctionCall1(tintervalrel,
TimeIntervalGetDatum(i)));
- PG_RETURN_BOOL((rt != INVALID_RELTIME) && (rt >= t));
+ PG_RETURN_BOOL(rt != INVALID_RELTIME && rt >= t);
}
/*
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.122 2005/05/23 21:54:02 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.123 2005/05/24 02:09:45 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#ifdef HAVE_INT64_TIMESTAMP
if (*time >= INT64CONST(0))
{
- *time = (((*time + TimestampOffsets[typmod]) / TimestampScales[typmod])
- * TimestampScales[typmod]);
+ *time = ((*time + TimestampOffsets[typmod]) / TimestampScales[typmod]) *
+ TimestampScales[typmod];
}
else
{
* TimestampScales[typmod]);
}
#else
- *time = (rint(((double) *time) * TimestampScales[typmod])
- / TimestampScales[typmod]);
+ *time = rint((double)*time * TimestampScales[typmod]) / TimestampScales[typmod];
#endif
}
}
#ifdef HAVE_INT64_TIMESTAMP
if (interval->time >= INT64CONST(0))
{
- interval->time = (((interval->time +
+ interval->time = ((interval->time +
IntervalOffsets[precision]) /
IntervalScales[precision]) *
IntervalScales[precision];
{
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))
- + tm->tm_min) * INT64CONST(60))
- + tm->tm_sec) * USECS_PER_SEC) + fsec);
+ span->time = (((((((tm->tm_mday * INT64CONST(24)) +
+ tm->tm_hour) * INT64CONST(60)) +
+ tm->tm_min) * INT64CONST(60)) +
+ tm->tm_sec) * USECS_PER_SEC) + fsec;
#else
- span->time = ((((((tm->tm_mday * 24.0)
- + tm->tm_hour) * 60.0)
- + tm->tm_min) * 60.0)
- + tm->tm_sec);
+ span->time = (((((tm->tm_mday * 24.0) +
+ tm->tm_hour) * 60.0) +
+ tm->tm_min) * 60.0) +
+ tm->tm_sec;
span->time = JROUND(span->time + fsec);
#endif
static int64
time2t(const int hour, const int min, const int sec, const fsec_t fsec)
{
- return ((((((hour * 60) + min) * 60) + sec) * USECS_PER_SEC) + fsec);
+ return (((((hour * 60) + min) * 60) + sec) * USECS_PER_SEC) + fsec;
} /* time2t() */
#else
static double
time2t(const int hour, const int min, const int sec, const fsec_t fsec)
{
- return ((((hour * 60) + min) * 60) + sec + fsec);
+ return (((hour * 60) + min) * 60) + sec + fsec;
} /* time2t() */
#endif
timestamp_cmp_internal(Timestamp dt1, Timestamp dt2)
{
#ifdef HAVE_INT64_TIMESTAMP
- return ((dt1 < dt2) ? -1 : ((dt1 > dt2) ? 1 : 0));
+ return (dt1 < dt2) ? -1 : ((dt1 > dt2) ? 1 : 0);
#else
/*
tm->tm_mon += span->month;
if (tm->tm_mon > 12)
{
- tm->tm_year += ((tm->tm_mon - 1) / 12);
- tm->tm_mon = (((tm->tm_mon - 1) % 12) + 1);
+ tm->tm_year += (tm->tm_mon - 1) / 12;
+ tm->tm_mon = ((tm->tm_mon - 1) % 12) + 1;
}
else if (tm->tm_mon < 1)
{
- tm->tm_year += ((tm->tm_mon / 12) - 1);
- tm->tm_mon = ((tm->tm_mon % 12) + 12);
+ tm->tm_year += tm->tm_mon / 12 - 1;
+ tm->tm_mon = tm->tm_mon % 12 + 12;
}
/* adjust for end of month boundary problems... */
tm->tm_mon += span->month;
if (tm->tm_mon > 12)
{
- tm->tm_year += ((tm->tm_mon - 1) / 12);
- tm->tm_mon = (((tm->tm_mon - 1) % 12) + 1);
+ tm->tm_year += (tm->tm_mon - 1) / 12;
+ tm->tm_mon = ((tm->tm_mon - 1) % 12) + 1;
}
else if (tm->tm_mon < 1)
{
- tm->tm_year += ((tm->tm_mon / 12) - 1);
- tm->tm_mon = ((tm->tm_mon % 12) + 12);
+ tm->tm_year += tm->tm_mon / 12 - 1;
+ tm->tm_mon = tm->tm_mon % 12 + 12;
}
/* adjust for end of month boundary problems... */
timestamp2tm(dt2, NULL, tm2, &fsec2, NULL) == 0)
{
fsec = (fsec1 - fsec2);
- tm->tm_sec = (tm1->tm_sec - tm2->tm_sec);
- tm->tm_min = (tm1->tm_min - tm2->tm_min);
- tm->tm_hour = (tm1->tm_hour - tm2->tm_hour);
- tm->tm_mday = (tm1->tm_mday - tm2->tm_mday);
- tm->tm_mon = (tm1->tm_mon - tm2->tm_mon);
- tm->tm_year = (tm1->tm_year - tm2->tm_year);
+ tm->tm_sec = tm1->tm_sec - tm2->tm_sec;
+ tm->tm_min = tm1->tm_min - tm2->tm_min;
+ tm->tm_hour = tm1->tm_hour - tm2->tm_hour;
+ tm->tm_mday = tm1->tm_mday - tm2->tm_mday;
+ tm->tm_mon = tm1->tm_mon - tm2->tm_mon;
+ tm->tm_year = tm1->tm_year - tm2->tm_year;
/* flip sign if necessary... */
if (dt1 < dt2)
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);
- tm->tm_min = (tm1->tm_min - tm2->tm_min);
- tm->tm_hour = (tm1->tm_hour - tm2->tm_hour);
- tm->tm_mday = (tm1->tm_mday - tm2->tm_mday);
- tm->tm_mon = (tm1->tm_mon - tm2->tm_mon);
- tm->tm_year = (tm1->tm_year - tm2->tm_year);
+ fsec = fsec1 - fsec2;
+ tm->tm_sec = tm1->tm_sec - tm2->tm_sec;
+ tm->tm_min = tm1->tm_min - tm2->tm_min;
+ tm->tm_hour = tm1->tm_hour - tm2->tm_hour;
+ tm->tm_mday = tm1->tm_mday - tm2->tm_mday;
+ tm->tm_mon = tm1->tm_mon - tm2->tm_mon;
+ tm->tm_year = tm1->tm_year - tm2->tm_year;
/* flip sign if necessary... */
if (dt1 < dt2)
case DTK_YEAR:
tm->tm_mon = 0;
case DTK_QUARTER:
- tm->tm_mon = (3 * (tm->tm_mon / 3));
+ tm->tm_mon = 3 * (tm->tm_mon / 3);
case DTK_MONTH:
tm->tm_mday = 0;
case DTK_DAY:
* ----
*/
if (tm->tm_year > 0)
- result = ((tm->tm_year + 99) / 100);
+ result = (tm->tm_year + 99) / 100;
else
/* caution: C division may have negative remainder */
result = -((99 - (tm->tm_year - 1)) / 100);
errmsg("timestamp out of range")));
#ifdef HAVE_INT64_TIMESTAMP
- result = ((timestamptz - SetEpochTimestamp()) / 1000000e0);
+ result = (timestamptz - SetEpochTimestamp()) / 1000000e0;
#else
result = timestamptz - SetEpochTimestamp();
#endif
return INT_MIN;
}
- if ((ParseDateTime(str, lowstr, field, ftype, MAXDATEFIELDS, &nf, ptr) != 0)
- || (DecodeDateTime(field, ftype, nf, &dtype, tm, &fsec, &tzp, EuroDates) != 0))
+ if (ParseDateTime(str, lowstr, field, ftype, MAXDATEFIELDS, &nf, ptr) != 0 ||
+ DecodeDateTime(field, ftype, nf, &dtype, tm, &fsec, &tzp, EuroDates) != 0)
{
errno = PGTYPES_DATE_BAD_DATE;
return INT_MIN;
int DateStyle = 1;
bool EuroDates = FALSE;
- j2date((dDate + date2j(2000, 1, 1)), &(tm->tm_year), &(tm->tm_mon), &(tm->tm_mday));
+ j2date(dDate + date2j(2000, 1, 1), &(tm->tm_year), &(tm->tm_mon), &(tm->tm_mday));
EncodeDateOnly(tm, DateStyle, buf, EuroDates);
return pgtypes_strdup(buf);
}
strcpy(outbuf, fmtstring);
/* get the date */
- j2date((dDate + date2j(2000, 1, 1)), &(tm.tm_year), &(tm.tm_mon), &(tm.tm_mday));
+ j2date(dDate + date2j(2000, 1, 1), &(tm.tm_year), &(tm.tm_mon), &(tm.tm_mday));
dow = PGTYPESdate_dayofweek(dDate);
for (i = 0; mapping[i].format != NULL; i++)
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;
quad = julian / 1461;
julian -= quad * 1461;
y = julian * 4 / 1461;
- julian = ((y != 0) ? ((julian + 305) % 365) : ((julian + 306) % 366))
- + 123;
+ julian = ((y != 0) ? (julian + 305) % 365 : (julian + 306) % 366) + 123;
y += quad * 4;
*year = y - 4800;
quad = julian * 2141 / 65536;
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
{
int
EncodeDateOnly(struct tm * tm, int style, char *str, bool EuroDates)
{
- 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 len = strlen(str);
/* 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';
/* 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);
#else
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);
#endif
TrimTrailingZeros(str);
}
else
- sprintf((str + strlen(str)), ":%02d", tm->tm_sec);
+ sprintf(str + strlen(str), ":%02d", tm->tm_sec);
if (tm->tm_year <= 0)
- sprintf((str + strlen(str)), " BC");
+ sprintf(str + strlen(str), " BC");
/*
* tzp == NULL indicates that we don't want *any* time zone
* have alpha time zone info available. tm_isdst != -1
* indicates that we have a valid time zone translation.
*/
- if ((tzp != NULL) && (tm->tm_isdst >= 0))
+ 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);
}
break;
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);
#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);
#endif
TrimTrailingZeros(str);
}
else
- sprintf((str + strlen(str)), ":%02d", tm->tm_sec);
+ sprintf(str + strlen(str), ":%02d", tm->tm_sec);
if (tm->tm_year <= 0)
- sprintf((str + strlen(str)), " BC");
+ sprintf(str + strlen(str), " BC");
- if ((tzp != NULL) && (tm->tm_isdst >= 0))
+ 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);
}
}
break;
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);
#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);
#endif
TrimTrailingZeros(str);
}
else
- sprintf((str + strlen(str)), ":%02d", tm->tm_sec);
+ sprintf(str + strlen(str), ":%02d", tm->tm_sec);
if (tm->tm_year <= 0)
- sprintf((str + strlen(str)), " BC");
+ sprintf(str + strlen(str), " BC");
- if ((tzp != NULL) && (tm->tm_isdst >= 0))
+ 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);
}
}
break;
tm->tm_wday = (int) ((day + date2j(2000, 1, 1) + 1) % 7);
strncpy(str, days[tm->tm_wday], 3);
- strcpy((str + 3), " ");
+ strcpy(str + 3, " ");
if (EuroDates)
- 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);
#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);
#endif
TrimTrailingZeros(str);
}
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 (tm->tm_year <= 0)
- sprintf((str + strlen(str)), " BC");
+ sprintf(str + strlen(str), " BC");
- if ((tzp != NULL) && (tm->tm_isdst >= 0))
+ 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);
}
}
break;
#elif defined(HAVE_INT_TIMEZONE)
if (tzp != NULL)
{
- *tzp = ((tm->tm_isdst > 0) ? (TIMEZONE_GLOBAL - 3600) : TIMEZONE_GLOBAL);
+ *tzp = (tm->tm_isdst > 0) ? TIMEZONE_GLOBAL - 3600 : TIMEZONE_GLOBAL;
if (tzn != NULL)
{
/* indicate timezone unknown */
tmp->tm_isdst = -1;
- if (mktime(tmp) != ((time_t) -1) &&
- tmp->tm_isdst >= 0)
+ if (mktime(tmp) != (time_t)-1 && tmp->tm_isdst >= 0)
{
/* mktime() succeeded, trust its result */
tm->tm_isdst = tmp->tm_isdst;
/* tm_gmtoff is Sun/DEC-ism */
tz = -(tmp->tm_gmtoff);
#elif defined(HAVE_INT_TIMEZONE)
- tz = ((tmp->tm_isdst > 0) ? (TIMEZONE_GLOBAL - 3600) : TIMEZONE_GLOBAL);
+ tz = (tmp->tm_isdst > 0) ? TIMEZONE_GLOBAL - 3600 : TIMEZONE_GLOBAL;
#endif /* HAVE_INT_TIMEZONE */
}
else
time = jd;
#ifdef HAVE_INT64_TIMESTAMP
- *hour = (time / USECS_PER_HOUR);
- time -= ((*hour) * USECS_PER_HOUR);
- *min = (time / USECS_PER_MINUTE);
- time -= ((*min) * USECS_PER_MINUTE);
- *sec = (time / USECS_PER_SEC);
- *fsec = (time - (*sec * USECS_PER_SEC));
+ *hour = time / USECS_PER_HOUR;
+ time -= (*hour) * USECS_PER_HOUR;
+ *min = time / USECS_PER_MINUTE;
+ time -= (*min) * USECS_PER_MINUTE;
+ *sec = time / USECS_PER_SEC;
+ *fsec = time - (*sec * USECS_PER_SEC);
#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
* string and then do the conversion to an integer.
*/
strcpy(fstr, (cp + 1));
- strcpy((fstr + strlen(fstr)), "000000");
+ strcpy(fstr + strlen(fstr), "000000");
*(fstr + 6) = '\0';
*fsec = strtol(fstr, NULL, 10);
#else
* More than two digits? Then could be a date or a run-together
* time: 2001.360 20011225 040506.789
*/
- if ((cp - str) > 2)
+ if (cp - str > 2)
return DecodeNumberField(flen, str, (fmask | DTK_DATE_M),
tmask, tm, fsec, is2digits, EuroDates);
return -1;
/* Special case day of year? */
- if ((flen == 3) && (fmask & DTK_M(YEAR))
- && ((val >= 1) && (val <= 366)))
+ if (flen == 3 && (fmask & DTK_M(YEAR)) && val >= 1 && val <= 366)
{
*tmask = (DTK_M(DOY) | DTK_M(MONTH) | DTK_M(DAY));
tm->tm_yday = val;
- j2date((date2j(tm->tm_year, 1, 1) + tm->tm_yday - 1),
+ j2date(date2j(tm->tm_year, 1, 1) + tm->tm_yday - 1,
&tm->tm_year, &tm->tm_mon, &tm->tm_mday);
}
*tmask = DTK_M(YEAR);
/* already have a year? then see if we can substitute... */
- if ((fmask & DTK_M(YEAR)) && (!(fmask & DTK_M(DAY)))
- && ((tm->tm_year >= 1) && (tm->tm_year <= 31)))
+ if ((fmask & DTK_M(YEAR)) && !(fmask & DTK_M(DAY)) &&
+ tm->tm_year >= 1 && tm->tm_year <= 31)
{
tm->tm_mday = tm->tm_year;
*tmask = DTK_M(DAY);
}
/* already have year? then could be month */
- else if ((fmask & DTK_M(YEAR)) && (!(fmask & DTK_M(MONTH)))
- && ((val >= 1) && (val <= 12)))
+ else if ((fmask & DTK_M(YEAR)) && !(fmask & DTK_M(MONTH)) && val >= 1 && val <= 12)
{
*tmask = DTK_M(MONTH);
tm->tm_mon = val;
}
/* no year and EuroDates enabled? then could be day */
- else if ((EuroDates || (fmask & DTK_M(MONTH)))
- && (!(fmask & DTK_M(YEAR)) && !(fmask & DTK_M(DAY)))
- && ((val >= 1) && (val <= 31)))
+ else if ((EuroDates || (fmask & DTK_M(MONTH))) &&
+ !(fmask & DTK_M(YEAR)) && !(fmask & DTK_M(DAY)) &&
+ val >= 1 && val <= 31)
{
*tmask = DTK_M(DAY);
tm->tm_mday = val;
}
- else if ((!(fmask & DTK_M(MONTH)))
- && ((val >= 1) && (val <= 12)))
+ else if (!(fmask & DTK_M(MONTH)) && val >= 1 && val <= 12)
{
*tmask = DTK_M(MONTH);
tm->tm_mon = val;
}
- else if ((!(fmask & DTK_M(DAY)))
- && ((val >= 1) && (val <= 31)))
+ else if (!(fmask & DTK_M(DAY)) && val >= 1 && val <= 31)
{
*tmask = DTK_M(DAY);
tm->tm_mday = val;
* Check for 2 or 4 or more digits, but currently we reach here only
* if two digits. - thomas 2000-03-28
*/
- else if (!(fmask & DTK_M(YEAR))
- && ((flen >= 4) || (flen == 2)))
+ else if (!(fmask & DTK_M(YEAR)) && (flen >= 4 || flen == 2))
{
*tmask = DTK_M(YEAR);
tm->tm_year = val;
char *field[MAXDATEFIELDS];
/* parse this string... */
- while ((*str != '\0') && (nf < MAXDATEFIELDS))
+ while (*str != '\0' && nf < MAXDATEFIELDS)
{
/* skip field separators */
while (!isalnum((unsigned char) *str))
* integer.
*/
strncpy(fstr, (cp + 1), 7);
- strcpy((fstr + strlen(fstr)), "000000");
+ strcpy(fstr + strlen(fstr), "000000");
*(fstr + 6) = '\0';
*fsec = strtol(fstr, &cp, 10);
#else
/* 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 > 59)
- || (*fsec >= USECS_PER_SEC))
+ if (tm->tm_hour < 0 || tm->tm_min < 0 || tm->tm_min > 59 ||
+ tm->tm_sec < 0 || tm->tm_sec > 59 || *fsec >= USECS_PER_SEC)
return -1;
#else
- if ((tm->tm_hour < 0)
- || (tm->tm_min < 0) || (tm->tm_min > 59)
- || (tm->tm_sec < 0) || (tm->tm_sec > 59)
- || (*fsec >= 1))
+ if (tm->tm_hour < 0 || tm->tm_min < 0 || tm->tm_min > 59 ||
+ tm->tm_sec < 0 || tm->tm_sec > 59 || *fsec >= 1)
return -1;
#endif
int len;
/* assume leading character is "+" or "-" */
- 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') && ((len = strlen(str)) > 3))
+ else if (*cp == '\0' && (len = strlen(str)) > 3)
{
- min = strtol((str + len - 2), &cp, 10);
- if ((min < 0) || (min >= 60))
+ min = strtol(str + len - 2, &cp, 10);
+ if (min < 0 || min >= 60)
return -1;
*(str + len - 2) = '\0';
- hr = strtol((str + 1), &cp, 10);
- if ((hr < 0) || (hr > 13))
+ hr = strtol(str + 1, &cp, 10);
+ if (hr < 0 || hr > 13)
return -1;
}
else
char delim;
cp = str;
- while ((*cp != '\0') && isalpha((unsigned char) *cp))
+ while (*cp != '\0' && isalpha((unsigned char) *cp))
cp++;
if (DecodeTimezone(cp, &tz) != 0)
*lp++ = *(*endstr)++;
}
/* date field? allow embedded text month */
- else if ((*(*endstr) == '-') || (*(*endstr) == '/') || (*(*endstr) == '.'))
+ else if (*(*endstr) == '-' || *(*endstr) == '/' || *(*endstr) == '.')
{
/* save delimiting character to use later */
char *dp = (*endstr);
/* second field is all digits? then no embedded text month */
if (isdigit((unsigned char) *(*endstr)))
{
- ftype[nf] = ((*dp == '.') ? DTK_NUMBER : DTK_DATE);
+ ftype[nf] = (*dp == '.') ? DTK_NUMBER : DTK_DATE;
while (isdigit((unsigned char) *(*endstr)))
*lp++ = *(*endstr)++;
* Full date string with leading text month? Could also be a
* POSIX time zone...
*/
- if ((*(*endstr) == '-') || (*(*endstr) == '/') || (*(*endstr) == '.'))
+ if (*(*endstr) == '-' || *(*endstr) == '/' || *(*endstr) == '.')
{
char *dp = (*endstr);
ftype[nf] = DTK_DATE;
*lp++ = *(*endstr)++;
- while (isdigit((unsigned char) *(*endstr)) || (*(*endstr) == *dp))
+ while (isdigit((unsigned char) *(*endstr)) || *(*endstr) == *dp)
*lp++ = *(*endstr)++;
}
}
continue;
}
/* sign? then special or numeric timezone */
- else if ((*(*endstr) == '+') || (*(*endstr) == '-'))
+ else if (*(*endstr) == '+' || *(*endstr) == '-')
{
*lp++ = *(*endstr)++;
/* soak up leading whitespace */
* 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);
case DTK_TIME:
/* previous field was "t" for ISO time */
if ((ftype[i] = DecodeNumberField(strlen(field[i]), field[i], (fmask | DTK_DATE_M),
- &tmask, tm, fsec, &is2digits, EuroDates)) < 0)
+ &tmask, tm, fsec, &is2digits, EuroDates)) < 0)
return -1;
if (tmask != DTK_TIME_M)
cp = strchr(field[i], '.');
/* Embedded decimal and no date yet? */
- if ((cp != NULL) && !(fmask & DTK_DATE_M))
+ if (cp != NULL && !(fmask & DTK_DATE_M))
{
if (DecodeDate(field[i], fmask, &tmask, tm, EuroDates) != 0)
return -1;
}
/* 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
* later. Example: 20011223 or 040506
*/
if ((ftype[i] = DecodeNumberField(flen, field[i], fmask,
- &tmask, tm, fsec, &is2digits, EuroDates)) < 0)
+ &tmask, tm, fsec, &is2digits, EuroDates)) < 0)
return -1;
}
else if (flen > 4)
{
if ((ftype[i] = DecodeNumberField(flen, field[i], fmask,
- &tmask, tm, fsec, &is2digits, EuroDates)) < 0)
+ &tmask, tm, fsec, &is2digits, EuroDates)) < 0)
return -1;
}
/* otherwise it is a single date/time field... */
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 -1;
ptype = val;
tm->tm_year += 1900;
}
- if ((mer != HR24) && (tm->tm_hour > 12))
+ if (mer != HR24 && tm->tm_hour > 12)
return -1;
- 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... */
* check for valid day of month, now that we know for sure the
* month and year...
*/
- if ((tm->tm_mday < 1)
- || (tm->tm_mday > day_tab[isleap(tm->tm_year)][tm->tm_mon - 1]))
+ if (tm->tm_mday < 1 || tm->tm_mday > day_tab[isleap(tm->tm_year)][tm->tm_mon - 1])
return -1;
/* timezone not specified? then find local timezone if possible */
- if (((fmask & DTK_DATE_M) == DTK_DATE_M)
- && (tzp != NULL) && (!(fmask & DTK_M(TZ))))
+ if ((fmask & DTK_DATE_M) == DTK_DATE_M && tzp != NULL && !(fmask & DTK_M(TZ)))
{
/*
* daylight savings time modifier but no standard timezone?
int len = strlen(str);
/* 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';
* integer.
*/
strncpy(fstr, (cp + 1), 7);
- strcpy((fstr + strlen(fstr)), "000000");
+ strcpy(fstr + strlen(fstr), "000000");
*(fstr + 6) = '\0';
*fsec = strtol(fstr, &cp, 10);
#else
/* 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 > 59)
- || (*fsec >= USECS_PER_SEC))
+ if (tm->tm_hour < 0 || tm->tm_min < 0 || tm->tm_min > 59 ||
+ tm->tm_sec < 0 || tm->tm_sec > 59 || *fsec >= USECS_PER_SEC)
return -1;
#else
- if ((tm->tm_hour < 0)
- || (tm->tm_min < 0) || (tm->tm_min > 59)
- || (tm->tm_sec < 0) || (tm->tm_sec > 59)
- || (*fsec >= 1))
+ if (tm->tm_hour < 0 || tm->tm_min < 0 || tm->tm_min > 59 ||
+ tm->tm_sec < 0 || tm->tm_sec > 59 || *fsec >= 1)
return -1;
#endif
* 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] == '-')
{
return -1;
if (val < 0)
- fval = -(fval);
+ fval = -fval;
}
else if (*cp == '\0')
fval = 0;
{
case DTK_MICROSEC:
#ifdef HAVE_INT64_TIMESTAMP
- *fsec += (val + fval);
+ *fsec += val + fval;
#else
- *fsec += ((val + fval) * 1e-6);
+ *fsec += (val + fval) * 1e-6;
#endif
break;
case DTK_MILLISEC:
#ifdef HAVE_INT64_TIMESTAMP
- *fsec += ((val + fval) * 1000);
+ *fsec += (val + fval) * 1000;
#else
- *fsec += ((val + fval) * 1e-3);
+ *fsec += (val + fval) * 1e-3;
#endif
break;
case DTK_SECOND:
tm->tm_sec += val;
#ifdef HAVE_INT64_TIMESTAMP
- *fsec += (fval * 1000000);
+ *fsec += fval * 1000000;
#else
*fsec += fval;
#endif
sec = fval;
tm->tm_sec += sec;
#ifdef HAVE_INT64_TIMESTAMP
- *fsec += ((fval - sec) * 1000000);
+ *fsec += (fval - sec) * 1000000;
#else
*fsec += (fval - sec);
#endif
sec = fval;
tm->tm_sec += sec;
#ifdef HAVE_INT64_TIMESTAMP
- *fsec += ((fval - sec) * 1000000);
+ *fsec += (fval - sec) * 1000000;
#else
*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:
{
int sec;
- fval *= (7 * SECS_PER_DAY);
+ fval *= 7 * SECS_PER_DAY;
sec = fval;
tm->tm_sec += sec;
#ifdef HAVE_INT64_TIMESTAMP
- *fsec += ((fval - sec) * 1000000);
+ *fsec += (fval - sec) * 1000000;
#else
*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:
{
int sec;
- fval *= (30 * SECS_PER_DAY);
+ fval *= 30 * SECS_PER_DAY;
sec = fval;
tm->tm_sec += sec;
#ifdef HAVE_INT64_TIMESTAMP
- *fsec += ((fval - sec) * 1000000);
+ *fsec += (fval - sec) * 1000000;
#else
*fsec += (fval - sec);
#endif
case DTK_YEAR:
tm->tm_year += val;
if (fval != 0)
- tm->tm_mon += (fval * 12);
- tmask = ((fmask & DTK_M(YEAR)) ? 0 : DTK_M(YEAR));
+ tm->tm_mon += fval * 12;
+ 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));
+ tm->tm_mon += fval * 120;
+ 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));
+ tm->tm_mon += fval * 1200;
+ 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));
+ tm->tm_mon += fval * 12000;
+ tmask = (fmask & DTK_M(YEAR)) ? 0 : DTK_M(YEAR);
break;
default:
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 ? " " : ""),
(minus ? "-" : (is_before ? "+" : "")),
#ifdef HAVE_INT64_TIMESTAMP
sprintf(cp, ":%02d", abs(tm->tm_sec));
cp += strlen(cp);
- sprintf(cp, ".%06d", ((fsec >= 0) ? fsec : -(fsec)));
+ sprintf(cp, ".%06d", (fsec >= 0) ? fsec : -(fsec));
#else
fsec += tm->tm_sec;
sprintf(cp, ":%013.10f", fabs(fsec));
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);
if (fsec != 0)
{
#ifdef HAVE_INT64_TIMESTAMP
- if (is_before || ((!is_nonzero) && (tm->tm_sec < 0)))
+ if (is_before || (!is_nonzero && tm->tm_sec < 0))
tm->tm_sec = -tm->tm_sec;
- sprintf(cp, "%s%d.%02d secs", (is_nonzero ? " " : ""),
- tm->tm_sec, (((int) fsec) / 10000));
+ sprintf(cp, "%s%d.%02d secs", is_nonzero ? " " : "",
+ tm->tm_sec, ((int) fsec) / 10000);
cp += strlen(cp);
if (!is_nonzero)
is_before = (fsec < 0);
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);
static int
tm2interval(struct 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))
- + tm->tm_min) * INT64CONST(60))
- + tm->tm_sec) * USECS_PER_SEC) + fsec);
+ span->time = (((((((tm->tm_mday * INT64CONST(24)) +
+ tm->tm_hour) * INT64CONST(60)) +
+ tm->tm_min) * INT64CONST(60)) +
+ tm->tm_sec) * USECS_PER_SEC) + fsec;
#else
- span->time = ((((((tm->tm_mday * 24.0)
- + tm->tm_hour) * 60.0)
- + tm->tm_min) * 60.0)
- + tm->tm_sec);
+ span->time = (((((tm->tm_mday * 24.0) +
+ tm->tm_hour) * 60.0) +
+ tm->tm_min) * 60.0) +
+ tm->tm_sec;
span->time = JROUND(span->time + fsec);
#endif
return NULL;
}
- if ((ParseDateTime(str, lowstr, field, ftype, MAXDATEFIELDS, &nf, ptr) != 0)
- || (DecodeInterval(field, ftype, nf, &dtype, tm, &fsec) != 0))
+ if (ParseDateTime(str, lowstr, field, ftype, MAXDATEFIELDS, &nf, ptr) != 0 ||
+ DecodeInterval(field, ftype, nf, &dtype, tm, &fsec) != 0)
{
errno = PGTYPES_INTVL_BAD_INTERVAL;
return NULL;
char *endptr;
(*ptr)++;
- exponent = strtol((*ptr), &endptr, 10);
+ exponent = strtol(*ptr, &endptr, 10);
if (endptr == (*ptr))
{
errno = PGTYPES_NUM_BAD_NUMERIC;
{
size++;
reach_limit *= 10;
- } while ((reach_limit - 1) < abs_long_val && reach_limit <= LONG_MAX / 10);
+ } while (reach_limit - 1 < abs_long_val && reach_limit <= LONG_MAX / 10);
if (reach_limit > LONG_MAX / 10)
{
static int64
time2t(const int hour, const int min, const int sec, const fsec_t fsec)
{
- return ((((((hour * 60) + min) * 60) + sec) * USECS_PER_SEC) + fsec);
+ return (((((hour * 60) + min) * 60) + sec) * USECS_PER_SEC) + fsec;
} /* time2t() */
#else
static double
time2t(const int hour, const int min, const int sec, const fsec_t fsec)
{
- return ((((hour * 60) + min) * 60) + sec + fsec);
+ return (((hour * 60) + min) * 60) + sec + fsec;
} /* time2t() */
#endif
if ((*result - time) / USECS_PER_DAY != dDate)
return -1;
/* check for just-barely overflow (okay except time-of-day wraps) */
- if ((*result < 0) ? (dDate >= 0) : (dDate < 0))
+ if ((*result < 0 && dDate >= 0) ||
+ (*result >= 0 && dDate < 0))
return -1;
#else
- *result = ((dDate * SECS_PER_DAY) + time);
+ *result = dDate * SECS_PER_DAY + time;
#endif
if (tzp != NULL)
*result = dt2local(*result, -(*tzp));
time = jd;
#ifdef HAVE_INT64_TIMESTAMP
- *hour = (time / USECS_PER_HOUR);
- time -= ((*hour) * USECS_PER_HOUR);
- *min = (time / USECS_PER_MINUTE);
- time -= ((*min) * USECS_PER_MINUTE);
- *sec = (time / USECS_PER_SEC);
- *fsec = (time - (*sec * USECS_PER_SEC));
- *sec = (time / USECS_PER_SEC);
- *fsec = (time - (*sec * USECS_PER_SEC));
+ *hour = time / USECS_PER_HOUR;
+ time -= (*hour) * USECS_PER_HOUR;
+ *min = time / USECS_PER_MINUTE;
+ time -= (*min) * USECS_PER_MINUTE;
+ *sec = time / USECS_PER_SEC;
+ *fsec = time - *sec * USECS_PER_SEC;
+ *sec = time / USECS_PER_SEC;
+ *fsec = time - *sec * USECS_PER_SEC;
#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 (IS_VALID_UTIME(tm->tm_year, tm->tm_mon, tm->tm_mday))
{
#ifdef HAVE_INT64_TIMESTAMP
- utime = ((dt / USECS_PER_SEC)
- + ((date0 - date2j(1970, 1, 1)) * INT64CONST(SECS_PER_DAY)));
+ utime = dt / USECS_PER_SEC +
+ ((date0 - date2j(1970, 1, 1)) * INT64CONST(86400));
#else
- utime = (dt + ((date0 - date2j(1970, 1, 1)) * SECS_PER_DAY));
+ utime = dt + (date0 - date2j(1970, 1, 1)) * SECS_PER_DAY;
#endif
#if defined(HAVE_TM_ZONE) || defined(HAVE_INT_TIMEZONE)
if (tzn != NULL)
*tzn = (char *) tm->tm_zone;
#elif defined(HAVE_INT_TIMEZONE)
- *tzp = ((tm->tm_isdst > 0) ? (TIMEZONE_GLOBAL - 3600) : TIMEZONE_GLOBAL);
+ *tzp = (tm->tm_isdst > 0) ? TIMEZONE_GLOBAL - 3600 : TIMEZONE_GLOBAL;
if (tzn != NULL)
*tzn = TZNAME_GLOBAL[(tm->tm_isdst > 0)];
#endif
return (noresult);
}
- if ((ParseDateTime(str, lowstr, field, ftype, MAXDATEFIELDS, &nf, ptr) != 0)
- || (DecodeDateTime(field, ftype, nf, &dtype, tm, &fsec, &tz, 0) != 0))
+ if (ParseDateTime(str, lowstr, field, ftype, MAXDATEFIELDS, &nf, ptr) != 0 ||
+ DecodeDateTime(field, ftype, nf, &dtype, tm, &fsec, &tz, 0) != 0)
{
errno = PGTYPES_TS_BAD_TIMESTAMP;
return (noresult);
break;
case 's':
#ifdef HAVE_INT64_TIMESTAMP
- replace_val.int64_val = ((*ts - SetEpochTimestamp()) / 1000000e0);
+ replace_val.int64_val = (*ts - SetEpochTimestamp()) / 1000000e0;
replace_type = PGTYPES_TYPE_INT64;
#else
replace_val.double_val = *ts - SetEpochTimestamp();
tm->tm_mon += span->month;
if (tm->tm_mon > 12)
{
- tm->tm_year += ((tm->tm_mon - 1) / 12);
- tm->tm_mon = (((tm->tm_mon - 1) % 12) + 1);
+ tm->tm_year += (tm->tm_mon - 1) / 12;
+ tm->tm_mon = (tm->tm_mon - 1) % 12 + 1;
}
else if (tm->tm_mon < 1)
{
- tm->tm_year += ((tm->tm_mon / 12) - 1);
- tm->tm_mon = ((tm->tm_mon % 12) + 12);
+ tm->tm_year += tm->tm_mon / 12 - 1;
+ tm->tm_mon = tm->tm_mon % 12 + 12;
}