mirror of
https://github.com/postgres/postgres.git
synced 2025-06-06 00:02:36 -04:00
Remove unnecessary parentheses in datetime/timestamp code.
This commit is contained in:
parent
c1393173aa
commit
33d0d4ce96
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* 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 $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -684,7 +684,7 @@ TrimTrailingZeros(char *str)
|
|||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
/* chop off trailing one to cope with interval rounding */
|
/* 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;
|
len -= 4;
|
||||||
*(str + len) = '\0';
|
*(str + len) = '\0';
|
||||||
@ -692,8 +692,7 @@ TrimTrailingZeros(char *str)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* chop off trailing zeros... but leave at least 2 fractional digits */
|
/* chop off trailing zeros... but leave at least 2 fractional digits */
|
||||||
while ((*(str + len - 1) == '0')
|
while (*(str + len - 1) == '0' && *(str + len - 3) != '.')
|
||||||
&& (*(str + len - 3) != '.'))
|
|
||||||
{
|
{
|
||||||
len--;
|
len--;
|
||||||
*(str + len) = '\0';
|
*(str + len) = '\0';
|
||||||
@ -769,7 +768,7 @@ ParseDateTime(const char *timestr, char *lowstr,
|
|||||||
*lp++ = *cp++;
|
*lp++ = *cp++;
|
||||||
}
|
}
|
||||||
/* date field? allow embedded text month */
|
/* date field? allow embedded text month */
|
||||||
else if ((*cp == '-') || (*cp == '/') || (*cp == '.'))
|
else if (*cp == '-' || *cp == '/' || *cp == '.')
|
||||||
{
|
{
|
||||||
/* save delimiting character to use later */
|
/* save delimiting character to use later */
|
||||||
char delim = *cp;
|
char delim = *cp;
|
||||||
@ -790,14 +789,14 @@ ParseDateTime(const char *timestr, char *lowstr,
|
|||||||
{
|
{
|
||||||
ftype[nf] = DTK_DATE;
|
ftype[nf] = DTK_DATE;
|
||||||
*lp++ = *cp++;
|
*lp++ = *cp++;
|
||||||
while (isdigit((unsigned char) *cp) || (*cp == delim))
|
while (isdigit((unsigned char) *cp) || *cp == delim)
|
||||||
*lp++ = *cp++;
|
*lp++ = *cp++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ftype[nf] = DTK_DATE;
|
ftype[nf] = DTK_DATE;
|
||||||
while (isalnum((unsigned char) *cp) || (*cp == delim))
|
while (isalnum((unsigned char) *cp) || *cp == delim)
|
||||||
*lp++ = pg_tolower((unsigned char) *cp++);
|
*lp++ = pg_tolower((unsigned char) *cp++);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -834,18 +833,18 @@ ParseDateTime(const char *timestr, char *lowstr,
|
|||||||
* Full date string with leading text month? Could also be a
|
* Full date string with leading text month? Could also be a
|
||||||
* POSIX time zone...
|
* POSIX time zone...
|
||||||
*/
|
*/
|
||||||
if ((*cp == '-') || (*cp == '/') || (*cp == '.'))
|
if (*cp == '-' || *cp == '/' || *cp == '.')
|
||||||
{
|
{
|
||||||
char delim = *cp;
|
char delim = *cp;
|
||||||
|
|
||||||
ftype[nf] = DTK_DATE;
|
ftype[nf] = DTK_DATE;
|
||||||
*lp++ = *cp++;
|
*lp++ = *cp++;
|
||||||
while (isdigit((unsigned char) *cp) || (*cp == delim))
|
while (isdigit((unsigned char) *cp) || *cp == delim)
|
||||||
*lp++ = *cp++;
|
*lp++ = *cp++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* sign? then special or numeric timezone */
|
/* sign? then special or numeric timezone */
|
||||||
else if ((*cp == '+') || (*cp == '-'))
|
else if (*cp == '+' || *cp == '-')
|
||||||
{
|
{
|
||||||
*lp++ = *cp++;
|
*lp++ = *cp++;
|
||||||
/* soak up leading whitespace */
|
/* soak up leading whitespace */
|
||||||
@ -857,7 +856,7 @@ ParseDateTime(const char *timestr, char *lowstr,
|
|||||||
ftype[nf] = DTK_TZ;
|
ftype[nf] = DTK_TZ;
|
||||||
*lp++ = *cp++;
|
*lp++ = *cp++;
|
||||||
while (isdigit((unsigned char) *cp) ||
|
while (isdigit((unsigned char) *cp) ||
|
||||||
(*cp == ':') || (*cp == '.'))
|
*cp == ':' || *cp == '.')
|
||||||
*lp++ = *cp++;
|
*lp++ = *cp++;
|
||||||
}
|
}
|
||||||
/* special? */
|
/* special? */
|
||||||
@ -982,8 +981,7 @@ DecodeDateTime(char **field, int *ftype, int nf,
|
|||||||
* a run-together time with trailing time zone (e.g. hhmmss-zz).
|
* a run-together time with trailing time zone (e.g. hhmmss-zz).
|
||||||
* - thomas 2001-12-25
|
* - thomas 2001-12-25
|
||||||
***/
|
***/
|
||||||
else if (((fmask & DTK_DATE_M) == DTK_DATE_M)
|
else if ((fmask & DTK_DATE_M) == DTK_DATE_M || ptype != 0)
|
||||||
|| (ptype != 0))
|
|
||||||
{
|
{
|
||||||
/* No time zone accepted? Then quit... */
|
/* No time zone accepted? Then quit... */
|
||||||
if (tzp == NULL)
|
if (tzp == NULL)
|
||||||
@ -1083,9 +1081,9 @@ DecodeDateTime(char **field, int *ftype, int nf,
|
|||||||
* second field of a POSIX time: EST+3 (equivalent to
|
* second field of a POSIX time: EST+3 (equivalent to
|
||||||
* PST)
|
* PST)
|
||||||
*/
|
*/
|
||||||
if ((i > 0) && ((fmask & DTK_M(TZ)) != 0)
|
if (i > 0 && (fmask & DTK_M(TZ)) != 0 &&
|
||||||
&& (ftype[i - 1] == DTK_TZ)
|
ftype[i - 1] == DTK_TZ &&
|
||||||
&& (isalpha((unsigned char) *field[i - 1])))
|
isalpha((unsigned char) *field[i - 1]))
|
||||||
{
|
{
|
||||||
*tzp -= tz;
|
*tzp -= tz;
|
||||||
tmask = 0;
|
tmask = 0;
|
||||||
@ -1142,8 +1140,8 @@ DecodeDateTime(char **field, int *ftype, int nf,
|
|||||||
* already have a month and hour? then assume
|
* already have a month and hour? then assume
|
||||||
* minutes
|
* minutes
|
||||||
*/
|
*/
|
||||||
if (((fmask & DTK_M(MONTH)) != 0)
|
if ((fmask & DTK_M(MONTH)) != 0 &&
|
||||||
&& ((fmask & DTK_M(HOUR)) != 0))
|
(fmask & DTK_M(HOUR)) != 0)
|
||||||
{
|
{
|
||||||
tm->tm_min = val;
|
tm->tm_min = val;
|
||||||
tmask = DTK_M(MINUTE);
|
tmask = DTK_M(MINUTE);
|
||||||
@ -1212,11 +1210,12 @@ DecodeDateTime(char **field, int *ftype, int nf,
|
|||||||
|
|
||||||
tmask |= DTK_TIME_M;
|
tmask |= DTK_TIME_M;
|
||||||
#ifdef HAVE_INT64_TIMESTAMP
|
#ifdef HAVE_INT64_TIMESTAMP
|
||||||
dt2time((time * INT64CONST(86400000000)),
|
dt2time(time * INT64CONST(86400000000),
|
||||||
&tm->tm_hour, &tm->tm_min, &tm->tm_sec, fsec);
|
&tm->tm_hour, &tm->tm_min,
|
||||||
|
&tm->tm_sec, fsec);
|
||||||
#else
|
#else
|
||||||
dt2time((time * 86400),
|
dt2time(time * 86400, &tm->tm_hour,
|
||||||
&tm->tm_hour, &tm->tm_min, &tm->tm_sec, fsec);
|
&tm->tm_min, &tm->tm_sec, fsec);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -1252,14 +1251,14 @@ DecodeDateTime(char **field, int *ftype, int nf,
|
|||||||
cp = strchr(field[i], '.');
|
cp = strchr(field[i], '.');
|
||||||
|
|
||||||
/* Embedded decimal and no date yet? */
|
/* 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);
|
dterr = DecodeDate(field[i], fmask, &tmask, tm);
|
||||||
if (dterr)
|
if (dterr)
|
||||||
return dterr;
|
return dterr;
|
||||||
}
|
}
|
||||||
/* embedded decimal and several digits before? */
|
/* 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
|
* Interpret as a concatenated date or time Set
|
||||||
@ -1325,8 +1324,8 @@ DecodeDateTime(char **field, int *ftype, int nf,
|
|||||||
tmask = DTK_DATE_M;
|
tmask = DTK_DATE_M;
|
||||||
*dtype = DTK_DATE;
|
*dtype = DTK_DATE;
|
||||||
GetCurrentDateTime(tm);
|
GetCurrentDateTime(tm);
|
||||||
j2date((date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) - 1),
|
j2date(date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) - 1,
|
||||||
&tm->tm_year, &tm->tm_mon, &tm->tm_mday);
|
&tm->tm_year, &tm->tm_mon, &tm->tm_mday);
|
||||||
tm->tm_hour = 0;
|
tm->tm_hour = 0;
|
||||||
tm->tm_min = 0;
|
tm->tm_min = 0;
|
||||||
tm->tm_sec = 0;
|
tm->tm_sec = 0;
|
||||||
@ -1345,8 +1344,8 @@ DecodeDateTime(char **field, int *ftype, int nf,
|
|||||||
tmask = DTK_DATE_M;
|
tmask = DTK_DATE_M;
|
||||||
*dtype = DTK_DATE;
|
*dtype = DTK_DATE;
|
||||||
GetCurrentDateTime(tm);
|
GetCurrentDateTime(tm);
|
||||||
j2date((date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) + 1),
|
j2date(date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) + 1,
|
||||||
&tm->tm_year, &tm->tm_mon, &tm->tm_mday);
|
&tm->tm_year, &tm->tm_mon, &tm->tm_mday);
|
||||||
tm->tm_hour = 0;
|
tm->tm_hour = 0;
|
||||||
tm->tm_min = 0;
|
tm->tm_min = 0;
|
||||||
tm->tm_sec = 0;
|
tm->tm_sec = 0;
|
||||||
@ -1374,9 +1373,9 @@ DecodeDateTime(char **field, int *ftype, int nf,
|
|||||||
* already have a (numeric) month? then see if we
|
* already have a (numeric) month? then see if we
|
||||||
* can substitute...
|
* can substitute...
|
||||||
*/
|
*/
|
||||||
if ((fmask & DTK_M(MONTH)) && (!haveTextMonth)
|
if ((fmask & DTK_M(MONTH)) && !haveTextMonth &&
|
||||||
&& (!(fmask & DTK_M(DAY)))
|
!(fmask & DTK_M(DAY)) && tm->tm_mon >= 1 &&
|
||||||
&& ((tm->tm_mon >= 1) && (tm->tm_mon <= 31)))
|
tm->tm_mon <= 31)
|
||||||
{
|
{
|
||||||
tm->tm_mday = tm->tm_mon;
|
tm->tm_mday = tm->tm_mon;
|
||||||
tmask = DTK_M(DAY);
|
tmask = DTK_M(DAY);
|
||||||
@ -1459,10 +1458,10 @@ DecodeDateTime(char **field, int *ftype, int nf,
|
|||||||
* DTK_TIME should be hh:mm:ss.fff
|
* DTK_TIME should be hh:mm:ss.fff
|
||||||
* DTK_DATE should be hhmmss-zz
|
* DTK_DATE should be hhmmss-zz
|
||||||
***/
|
***/
|
||||||
if ((i >= (nf - 1))
|
if (i >= nf - 1 ||
|
||||||
|| ((ftype[i + 1] != DTK_NUMBER)
|
(ftype[i + 1] != DTK_NUMBER &&
|
||||||
&& (ftype[i + 1] != DTK_TIME)
|
ftype[i + 1] != DTK_TIME &&
|
||||||
&& (ftype[i + 1] != DTK_DATE)))
|
ftype[i + 1] != DTK_DATE))
|
||||||
return DTERR_BAD_FORMAT;
|
return DTERR_BAD_FORMAT;
|
||||||
|
|
||||||
ptype = val;
|
ptype = val;
|
||||||
@ -1525,11 +1524,11 @@ DecodeDateTime(char **field, int *ftype, int nf,
|
|||||||
return DTERR_MD_FIELD_OVERFLOW;
|
return DTERR_MD_FIELD_OVERFLOW;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((mer != HR24) && (tm->tm_hour > 12))
|
if (mer != HR24 && tm->tm_hour > 12)
|
||||||
return DTERR_FIELD_OVERFLOW;
|
return DTERR_FIELD_OVERFLOW;
|
||||||
if ((mer == AM) && (tm->tm_hour == 12))
|
if (mer == AM && tm->tm_hour == 12)
|
||||||
tm->tm_hour = 0;
|
tm->tm_hour = 0;
|
||||||
else if ((mer == PM) && (tm->tm_hour != 12))
|
else if (mer == PM && tm->tm_hour != 12)
|
||||||
tm->tm_hour += 12;
|
tm->tm_hour += 12;
|
||||||
|
|
||||||
/* do additional checking for full date specs... */
|
/* do additional checking for full date specs... */
|
||||||
@ -1650,12 +1649,16 @@ DetermineLocalTimeZone(struct pg_tm * tm)
|
|||||||
* Form the candidate pg_time_t values with local-time adjustment
|
* Form the candidate pg_time_t values with local-time adjustment
|
||||||
*/
|
*/
|
||||||
beforetime = mytime - before_gmtoff;
|
beforetime = mytime - before_gmtoff;
|
||||||
if ((before_gmtoff > 0) ? (mytime < 0 && beforetime > 0) :
|
if ((before_gmtoff > 0 &&
|
||||||
(mytime > 0 && beforetime < 0))
|
mytime < 0 && beforetime > 0) ||
|
||||||
|
(before_gmtoff <= 0 &&
|
||||||
|
mytime > 0 && beforetime < 0))
|
||||||
goto overflow;
|
goto overflow;
|
||||||
aftertime = mytime - after_gmtoff;
|
aftertime = mytime - after_gmtoff;
|
||||||
if ((after_gmtoff > 0) ? (mytime < 0 && aftertime > 0) :
|
if ((after_gmtoff > 0 &&
|
||||||
(mytime > 0 && aftertime < 0))
|
mytime < 0 && aftertime > 0) ||
|
||||||
|
(after_gmtoff <= 0 &&
|
||||||
|
mytime > 0 && aftertime < 0))
|
||||||
goto overflow;
|
goto overflow;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1741,9 +1744,8 @@ DecodeTimeOnly(char **field, int *ftype, int nf,
|
|||||||
return DTERR_BAD_FORMAT;
|
return DTERR_BAD_FORMAT;
|
||||||
|
|
||||||
/* Under limited circumstances, we will accept a date... */
|
/* Under limited circumstances, we will accept a date... */
|
||||||
if ((i == 0) && (nf >= 2)
|
if (i == 0 && nf >= 2 &&
|
||||||
&& ((ftype[nf - 1] == DTK_DATE)
|
(ftype[nf - 1] == DTK_DATE || ftype[1] == DTK_TIME))
|
||||||
|| (ftype[1] == DTK_TIME)))
|
|
||||||
{
|
{
|
||||||
dterr = DecodeDate(field[i], fmask, &tmask, tm);
|
dterr = DecodeDate(field[i], fmask, &tmask, tm);
|
||||||
if (dterr)
|
if (dterr)
|
||||||
@ -1826,8 +1828,9 @@ DecodeTimeOnly(char **field, int *ftype, int nf,
|
|||||||
* second field of a POSIX time: EST+3 (equivalent to
|
* second field of a POSIX time: EST+3 (equivalent to
|
||||||
* PST)
|
* PST)
|
||||||
*/
|
*/
|
||||||
if ((i > 0) && ((fmask & DTK_M(TZ)) != 0)
|
if (i > 0 && (fmask & DTK_M(TZ)) != 0 &&
|
||||||
&& (ftype[i - 1] == DTK_TZ) && (isalpha((unsigned char) *field[i - 1])))
|
ftype[i - 1] == DTK_TZ &&
|
||||||
|
isalpha((unsigned char) *field[i - 1]))
|
||||||
{
|
{
|
||||||
*tzp -= tz;
|
*tzp -= tz;
|
||||||
tmask = 0;
|
tmask = 0;
|
||||||
@ -1897,8 +1900,8 @@ DecodeTimeOnly(char **field, int *ftype, int nf,
|
|||||||
* already have a month and hour? then assume
|
* already have a month and hour? then assume
|
||||||
* minutes
|
* minutes
|
||||||
*/
|
*/
|
||||||
if (((fmask & DTK_M(MONTH)) != 0)
|
if ((fmask & DTK_M(MONTH)) != 0 &&
|
||||||
&& ((fmask & DTK_M(HOUR)) != 0))
|
(fmask & DTK_M(HOUR)) != 0)
|
||||||
{
|
{
|
||||||
tm->tm_min = val;
|
tm->tm_min = val;
|
||||||
tmask = DTK_M(MINUTE);
|
tmask = DTK_M(MINUTE);
|
||||||
@ -1966,10 +1969,10 @@ DecodeTimeOnly(char **field, int *ftype, int nf,
|
|||||||
|
|
||||||
tmask |= DTK_TIME_M;
|
tmask |= DTK_TIME_M;
|
||||||
#ifdef HAVE_INT64_TIMESTAMP
|
#ifdef HAVE_INT64_TIMESTAMP
|
||||||
dt2time((time * INT64CONST(86400000000)),
|
dt2time(time * INT64CONST(86400000000),
|
||||||
&tm->tm_hour, &tm->tm_min, &tm->tm_sec, fsec);
|
&tm->tm_hour, &tm->tm_min, &tm->tm_sec, fsec);
|
||||||
#else
|
#else
|
||||||
dt2time((time * 86400),
|
dt2time(time * 86400,
|
||||||
&tm->tm_hour, &tm->tm_min, &tm->tm_sec, fsec);
|
&tm->tm_hour, &tm->tm_min, &tm->tm_sec, fsec);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -2012,14 +2015,14 @@ DecodeTimeOnly(char **field, int *ftype, int nf,
|
|||||||
* Under limited circumstances, we will accept a
|
* Under limited circumstances, we will accept a
|
||||||
* date...
|
* 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);
|
dterr = DecodeDate(field[i], fmask, &tmask, tm);
|
||||||
if (dterr)
|
if (dterr)
|
||||||
return dterr;
|
return dterr;
|
||||||
}
|
}
|
||||||
/* embedded decimal and several digits before? */
|
/* 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
|
* Interpret as a concatenated date or time
|
||||||
@ -2157,10 +2160,10 @@ DecodeTimeOnly(char **field, int *ftype, int nf,
|
|||||||
* DTK_TIME should be hh:mm:ss.fff
|
* DTK_TIME should be hh:mm:ss.fff
|
||||||
* DTK_DATE should be hhmmss-zz
|
* DTK_DATE should be hhmmss-zz
|
||||||
***/
|
***/
|
||||||
if ((i >= (nf - 1))
|
if (i >= nf - 1 ||
|
||||||
|| ((ftype[i + 1] != DTK_NUMBER)
|
(ftype[i + 1] != DTK_NUMBER &&
|
||||||
&& (ftype[i + 1] != DTK_TIME)
|
ftype[i + 1] != DTK_TIME &&
|
||||||
&& (ftype[i + 1] != DTK_DATE)))
|
ftype[i + 1] != DTK_DATE))
|
||||||
return DTERR_BAD_FORMAT;
|
return DTERR_BAD_FORMAT;
|
||||||
|
|
||||||
ptype = val;
|
ptype = val;
|
||||||
@ -2180,24 +2183,22 @@ DecodeTimeOnly(char **field, int *ftype, int nf,
|
|||||||
fmask |= tmask;
|
fmask |= tmask;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((mer != HR24) && (tm->tm_hour > 12))
|
if (mer != HR24 && tm->tm_hour > 12)
|
||||||
return DTERR_FIELD_OVERFLOW;
|
return DTERR_FIELD_OVERFLOW;
|
||||||
if ((mer == AM) && (tm->tm_hour == 12))
|
if (mer == AM && tm->tm_hour == 12)
|
||||||
tm->tm_hour = 0;
|
tm->tm_hour = 0;
|
||||||
else if ((mer == PM) && (tm->tm_hour != 12))
|
else if (mer == PM && tm->tm_hour != 12)
|
||||||
tm->tm_hour += 12;
|
tm->tm_hour += 12;
|
||||||
|
|
||||||
#ifdef HAVE_INT64_TIMESTAMP
|
#ifdef HAVE_INT64_TIMESTAMP
|
||||||
if ((tm->tm_hour < 0) || (tm->tm_hour > 23)
|
if (tm->tm_hour < 0 || tm->tm_hour > 23 || tm->tm_min < 0 ||
|
||||||
|| (tm->tm_min < 0) || (tm->tm_min > 59)
|
tm->tm_min > 59 || tm->tm_sec < 0 || tm->tm_sec > 60 ||
|
||||||
|| (tm->tm_sec < 0) || (tm->tm_sec > 60)
|
*fsec < INT64CONST(0) || *fsec >= INT64CONST(1000000))
|
||||||
|| (*fsec < INT64CONST(0)) || (*fsec >= INT64CONST(1000000)))
|
|
||||||
return DTERR_FIELD_OVERFLOW;
|
return DTERR_FIELD_OVERFLOW;
|
||||||
#else
|
#else
|
||||||
if ((tm->tm_hour < 0) || (tm->tm_hour > 23)
|
if (tm->tm_hour < 0 || tm->tm_hour > 23 || tm->tm_min < 0 ||
|
||||||
|| (tm->tm_min < 0) || (tm->tm_min > 59)
|
tm->tm_min > 59 || tm->tm_sec < 0 || tm->tm_sec > 60 ||
|
||||||
|| (tm->tm_sec < 0) || (tm->tm_sec > 60)
|
*fsec < 0 || *fsec >= 1)
|
||||||
|| (*fsec < 0) || (*fsec >= 1))
|
|
||||||
return DTERR_FIELD_OVERFLOW;
|
return DTERR_FIELD_OVERFLOW;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -2258,7 +2259,7 @@ DecodeDate(char *str, int fmask, int *tmask, struct pg_tm * tm)
|
|||||||
char *field[MAXDATEFIELDS];
|
char *field[MAXDATEFIELDS];
|
||||||
|
|
||||||
/* parse this string... */
|
/* parse this string... */
|
||||||
while ((*str != '\0') && (nf < MAXDATEFIELDS))
|
while (*str != '\0' && nf < MAXDATEFIELDS)
|
||||||
{
|
{
|
||||||
/* skip field separators */
|
/* skip field separators */
|
||||||
while (!isalnum((unsigned char) *str))
|
while (!isalnum((unsigned char) *str))
|
||||||
@ -2444,16 +2445,13 @@ DecodeTime(char *str, int fmask, int *tmask, struct pg_tm * tm, fsec_t *fsec)
|
|||||||
|
|
||||||
/* do a sanity check */
|
/* do a sanity check */
|
||||||
#ifdef HAVE_INT64_TIMESTAMP
|
#ifdef HAVE_INT64_TIMESTAMP
|
||||||
if ((tm->tm_hour < 0)
|
if (tm->tm_hour < 0 || tm->tm_min < 0 || tm->tm_min > 59 ||
|
||||||
|| (tm->tm_min < 0) || (tm->tm_min > 59)
|
tm->tm_sec < 0 || tm->tm_sec > 60 || *fsec < INT64CONST(0) ||
|
||||||
|| (tm->tm_sec < 0) || (tm->tm_sec > 60)
|
*fsec >= INT64CONST(1000000))
|
||||||
|| (*fsec < INT64CONST(0)) || (*fsec >= INT64CONST(1000000)))
|
|
||||||
return DTERR_FIELD_OVERFLOW;
|
return DTERR_FIELD_OVERFLOW;
|
||||||
#else
|
#else
|
||||||
if ((tm->tm_hour < 0)
|
if (tm->tm_hour < 0 || tm->tm_min < 0 || tm->tm_min > 59 ||
|
||||||
|| (tm->tm_min < 0) || (tm->tm_min > 59)
|
tm->tm_sec < 0 || tm->tm_sec > 60 || *fsec < 0 || *fsec >= 1)
|
||||||
|| (tm->tm_sec < 0) || (tm->tm_sec > 60)
|
|
||||||
|| (*fsec < 0) || (*fsec >= 1))
|
|
||||||
return DTERR_FIELD_OVERFLOW;
|
return DTERR_FIELD_OVERFLOW;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -2487,7 +2485,7 @@ DecodeNumber(int flen, char *str, bool haveTextMonth, int fmask,
|
|||||||
* More than two digits before decimal point? Then could be a date
|
* More than two digits before decimal point? Then could be a date
|
||||||
* or a run-together time: 2001.360 20011225 040506.789
|
* or a run-together time: 2001.360 20011225 040506.789
|
||||||
*/
|
*/
|
||||||
if ((cp - str) > 2)
|
if (cp - str > 2)
|
||||||
{
|
{
|
||||||
dterr = DecodeNumberField(flen, str,
|
dterr = DecodeNumberField(flen, str,
|
||||||
(fmask | DTK_DATE_M),
|
(fmask | DTK_DATE_M),
|
||||||
@ -2511,9 +2509,8 @@ DecodeNumber(int flen, char *str, bool haveTextMonth, int fmask,
|
|||||||
return DTERR_BAD_FORMAT;
|
return DTERR_BAD_FORMAT;
|
||||||
|
|
||||||
/* Special case for day of year */
|
/* Special case for day of year */
|
||||||
if ((flen == 3) &&
|
if (flen == 3 && (fmask & DTK_DATE_M) == DTK_M(YEAR) && val >= 1 &&
|
||||||
((fmask & DTK_DATE_M) == DTK_M(YEAR)) &&
|
val <= 366)
|
||||||
((val >= 1) && (val <= 366)))
|
|
||||||
{
|
{
|
||||||
*tmask = (DTK_M(DOY) | DTK_M(MONTH) | DTK_M(DAY));
|
*tmask = (DTK_M(DOY) | DTK_M(MONTH) | DTK_M(DAY));
|
||||||
tm->tm_yday = val;
|
tm->tm_yday = val;
|
||||||
@ -2764,13 +2761,13 @@ DecodeTimezone(char *str, int *tzp)
|
|||||||
if (*str != '+' && *str != '-')
|
if (*str != '+' && *str != '-')
|
||||||
return DTERR_BAD_FORMAT;
|
return DTERR_BAD_FORMAT;
|
||||||
|
|
||||||
hr = strtol((str + 1), &cp, 10);
|
hr = strtol(str + 1, &cp, 10);
|
||||||
|
|
||||||
/* explicit delimiter? */
|
/* explicit delimiter? */
|
||||||
if (*cp == ':')
|
if (*cp == ':')
|
||||||
min = strtol((cp + 1), &cp, 10);
|
min = strtol(cp + 1, &cp, 10);
|
||||||
/* otherwise, might have run things together... */
|
/* otherwise, might have run things together... */
|
||||||
else if ((*cp == '\0') && (strlen(str) > 3))
|
else if (*cp == '\0' && strlen(str) > 3)
|
||||||
{
|
{
|
||||||
min = hr % 100;
|
min = hr % 100;
|
||||||
hr = hr / 100;
|
hr = hr / 100;
|
||||||
@ -2778,9 +2775,9 @@ DecodeTimezone(char *str, int *tzp)
|
|||||||
else
|
else
|
||||||
min = 0;
|
min = 0;
|
||||||
|
|
||||||
if ((hr < 0) || (hr > 13))
|
if (hr < 0 || hr > 13)
|
||||||
return DTERR_TZDISP_OVERFLOW;
|
return DTERR_TZDISP_OVERFLOW;
|
||||||
if ((min < 0) || (min >= 60))
|
if (min < 0 || min >= 60)
|
||||||
return DTERR_TZDISP_OVERFLOW;
|
return DTERR_TZDISP_OVERFLOW;
|
||||||
|
|
||||||
tz = (hr * 60 + min) * 60;
|
tz = (hr * 60 + min) * 60;
|
||||||
@ -2866,8 +2863,8 @@ DecodeSpecial(int field, char *lowtoken, int *val)
|
|||||||
int type;
|
int type;
|
||||||
datetkn *tp;
|
datetkn *tp;
|
||||||
|
|
||||||
if ((datecache[field] != NULL)
|
if (datecache[field] != NULL &&
|
||||||
&& (strncmp(lowtoken, datecache[field]->token, TOKMAXLEN) == 0))
|
strncmp(lowtoken, datecache[field]->token, TOKMAXLEN) == 0)
|
||||||
tp = datecache[field];
|
tp = datecache[field];
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -2957,7 +2954,7 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct pg_tm * tm,
|
|||||||
* Timezone is a token with a leading sign character and
|
* Timezone is a token with a leading sign character and
|
||||||
* otherwise the same as a non-signed time field
|
* 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
|
* A single signed number ends up here, but will be
|
||||||
@ -2965,10 +2962,10 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct pg_tm * tm,
|
|||||||
* through to DTK_NUMBER, which *can* tolerate this.
|
* through to DTK_NUMBER, which *can* tolerate this.
|
||||||
*/
|
*/
|
||||||
cp = field[i] + 1;
|
cp = field[i] + 1;
|
||||||
while ((*cp != '\0') && (*cp != ':') && (*cp != '.'))
|
while (*cp != '\0' && *cp != ':' && *cp != '.')
|
||||||
cp++;
|
cp++;
|
||||||
if ((*cp == ':') &&
|
if (*cp == ':' &&
|
||||||
(DecodeTime(field[i] + 1, fmask, &tmask, tm, fsec) == 0))
|
DecodeTime(field[i] + 1, fmask, &tmask, tm, fsec) == 0)
|
||||||
{
|
{
|
||||||
if (*field[i] == '-')
|
if (*field[i] == '-')
|
||||||
{
|
{
|
||||||
@ -3111,7 +3108,7 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct pg_tm * tm,
|
|||||||
*fsec += (fval - sec);
|
*fsec += (fval - sec);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
tmask = ((fmask & DTK_M(DAY)) ? 0 : DTK_M(DAY));
|
tmask = (fmask & DTK_M(DAY)) ? 0 : DTK_M(DAY);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DTK_WEEK:
|
case DTK_WEEK:
|
||||||
@ -3129,7 +3126,7 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct pg_tm * tm,
|
|||||||
*fsec += (fval - sec);
|
*fsec += (fval - sec);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
tmask = ((fmask & DTK_M(DAY)) ? 0 : DTK_M(DAY));
|
tmask = (fmask & DTK_M(DAY)) ? 0 : DTK_M(DAY);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DTK_MONTH:
|
case DTK_MONTH:
|
||||||
@ -3154,28 +3151,28 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct pg_tm * tm,
|
|||||||
tm->tm_year += val;
|
tm->tm_year += val;
|
||||||
if (fval != 0)
|
if (fval != 0)
|
||||||
tm->tm_mon += (fval * 12);
|
tm->tm_mon += (fval * 12);
|
||||||
tmask = ((fmask & DTK_M(YEAR)) ? 0 : DTK_M(YEAR));
|
tmask = (fmask & DTK_M(YEAR)) ? 0 : DTK_M(YEAR);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DTK_DECADE:
|
case DTK_DECADE:
|
||||||
tm->tm_year += val * 10;
|
tm->tm_year += val * 10;
|
||||||
if (fval != 0)
|
if (fval != 0)
|
||||||
tm->tm_mon += (fval * 120);
|
tm->tm_mon += (fval * 120);
|
||||||
tmask = ((fmask & DTK_M(YEAR)) ? 0 : DTK_M(YEAR));
|
tmask = (fmask & DTK_M(YEAR)) ? 0 : DTK_M(YEAR);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DTK_CENTURY:
|
case DTK_CENTURY:
|
||||||
tm->tm_year += val * 100;
|
tm->tm_year += val * 100;
|
||||||
if (fval != 0)
|
if (fval != 0)
|
||||||
tm->tm_mon += (fval * 1200);
|
tm->tm_mon += (fval * 1200);
|
||||||
tmask = ((fmask & DTK_M(YEAR)) ? 0 : DTK_M(YEAR));
|
tmask = (fmask & DTK_M(YEAR)) ? 0 : DTK_M(YEAR);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DTK_MILLENNIUM:
|
case DTK_MILLENNIUM:
|
||||||
tm->tm_year += val * 1000;
|
tm->tm_year += val * 1000;
|
||||||
if (fval != 0)
|
if (fval != 0)
|
||||||
tm->tm_mon += (fval * 12000);
|
tm->tm_mon += (fval * 12000);
|
||||||
tmask = ((fmask & DTK_M(YEAR)) ? 0 : DTK_M(YEAR));
|
tmask = (fmask & DTK_M(YEAR)) ? 0 : DTK_M(YEAR);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -3262,8 +3259,8 @@ DecodeUnits(int field, char *lowtoken, int *val)
|
|||||||
int type;
|
int type;
|
||||||
datetkn *tp;
|
datetkn *tp;
|
||||||
|
|
||||||
if ((deltacache[field] != NULL)
|
if (deltacache[field] != NULL &&
|
||||||
&& (strncmp(lowtoken, deltacache[field]->token, TOKMAXLEN) == 0))
|
strncmp(lowtoken, deltacache[field]->token, TOKMAXLEN) == 0)
|
||||||
tp = deltacache[field];
|
tp = deltacache[field];
|
||||||
else
|
else
|
||||||
tp = datebsearch(lowtoken, deltatktbl, szdeltatktbl);
|
tp = datebsearch(lowtoken, deltatktbl, szdeltatktbl);
|
||||||
@ -3276,7 +3273,7 @@ DecodeUnits(int field, char *lowtoken, int *val)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
type = tp->type;
|
type = tp->type;
|
||||||
if ((type == TZ) || (type == DTZ))
|
if (type == TZ || type == DTZ)
|
||||||
*val = FROMVAL(tp);
|
*val = FROMVAL(tp);
|
||||||
else
|
else
|
||||||
*val = tp->value;
|
*val = tp->value;
|
||||||
@ -3372,7 +3369,7 @@ datebsearch(char *key, datetkn *base, unsigned int nel)
|
|||||||
int
|
int
|
||||||
EncodeDateOnly(struct pg_tm * tm, int style, char *str)
|
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;
|
return -1;
|
||||||
|
|
||||||
switch (style)
|
switch (style)
|
||||||
@ -3394,18 +3391,18 @@ EncodeDateOnly(struct pg_tm * tm, int style, char *str)
|
|||||||
else
|
else
|
||||||
sprintf(str, "%02d/%02d", tm->tm_mon, tm->tm_mday);
|
sprintf(str, "%02d/%02d", tm->tm_mon, tm->tm_mday);
|
||||||
if (tm->tm_year > 0)
|
if (tm->tm_year > 0)
|
||||||
sprintf((str + 5), "/%04d", tm->tm_year);
|
sprintf(str + 5, "/%04d", tm->tm_year);
|
||||||
else
|
else
|
||||||
sprintf((str + 5), "/%04d %s", -(tm->tm_year - 1), "BC");
|
sprintf(str + 5, "/%04d %s", -(tm->tm_year - 1), "BC");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case USE_GERMAN_DATES:
|
case USE_GERMAN_DATES:
|
||||||
/* German-style date format */
|
/* German-style date format */
|
||||||
sprintf(str, "%02d.%02d", tm->tm_mday, tm->tm_mon);
|
sprintf(str, "%02d.%02d", tm->tm_mday, tm->tm_mon);
|
||||||
if (tm->tm_year > 0)
|
if (tm->tm_year > 0)
|
||||||
sprintf((str + 5), ".%04d", tm->tm_year);
|
sprintf(str + 5, ".%04d", tm->tm_year);
|
||||||
else
|
else
|
||||||
sprintf((str + 5), ".%04d %s", -(tm->tm_year - 1), "BC");
|
sprintf(str + 5, ".%04d %s", -(tm->tm_year - 1), "BC");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case USE_POSTGRES_DATES:
|
case USE_POSTGRES_DATES:
|
||||||
@ -3416,9 +3413,9 @@ EncodeDateOnly(struct pg_tm * tm, int style, char *str)
|
|||||||
else
|
else
|
||||||
sprintf(str, "%02d-%02d", tm->tm_mon, tm->tm_mday);
|
sprintf(str, "%02d-%02d", tm->tm_mon, tm->tm_mday);
|
||||||
if (tm->tm_year > 0)
|
if (tm->tm_year > 0)
|
||||||
sprintf((str + 5), "-%04d", tm->tm_year);
|
sprintf(str + 5, "-%04d", tm->tm_year);
|
||||||
else
|
else
|
||||||
sprintf((str + 5), "-%04d %s", -(tm->tm_year - 1), "BC");
|
sprintf(str + 5, "-%04d %s", -(tm->tm_year - 1), "BC");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3432,7 +3429,7 @@ EncodeDateOnly(struct pg_tm * tm, int style, char *str)
|
|||||||
int
|
int
|
||||||
EncodeTimeOnly(struct pg_tm * tm, fsec_t fsec, int *tzp, int style, char *str)
|
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;
|
return -1;
|
||||||
|
|
||||||
sprintf(str, "%02d:%02d", tm->tm_hour, tm->tm_min);
|
sprintf(str, "%02d:%02d", tm->tm_hour, tm->tm_min);
|
||||||
@ -3445,17 +3442,17 @@ EncodeTimeOnly(struct pg_tm * tm, fsec_t fsec, int *tzp, int style, char *str)
|
|||||||
if (fsec != 0)
|
if (fsec != 0)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_INT64_TIMESTAMP
|
#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
|
#else
|
||||||
sprintf((str + strlen(str)), ":%013.10f", tm->tm_sec + fsec);
|
sprintf(str + strlen(str), ":%013.10f", tm->tm_sec + fsec);
|
||||||
#endif
|
#endif
|
||||||
/* chop off trailing pairs of zeros... */
|
/* chop off trailing pairs of zeros... */
|
||||||
while ((strcmp((str + strlen(str) - 2), "00") == 0)
|
while (strcmp((str + strlen(str) - 2), "00") == 0 &&
|
||||||
&& (*(str + strlen(str) - 3) != '.'))
|
*(str + strlen(str) - 3) != '.')
|
||||||
*(str + strlen(str) - 2) = '\0';
|
*(str + strlen(str) - 2) = '\0';
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
sprintf((str + strlen(str)), ":%02d", tm->tm_sec);
|
sprintf(str + strlen(str), ":%02d", tm->tm_sec);
|
||||||
|
|
||||||
if (tzp != NULL)
|
if (tzp != NULL)
|
||||||
{
|
{
|
||||||
@ -3463,8 +3460,8 @@ EncodeTimeOnly(struct pg_tm * tm, fsec_t fsec, int *tzp, int style, char *str)
|
|||||||
min;
|
min;
|
||||||
|
|
||||||
hour = -(*tzp / 3600);
|
hour = -(*tzp / 3600);
|
||||||
min = ((abs(*tzp) / 60) % 60);
|
min = (abs(*tzp) / 60) % 60;
|
||||||
sprintf((str + strlen(str)), ((min != 0) ? "%+03d:%02d" : "%+03d"), hour, min);
|
sprintf(str + strlen(str), (min != 0) ? "%+03d:%02d" : "%+03d", hour, min);
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@ -3491,9 +3488,9 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style,
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Why are we checking only the month field? Change this to an
|
* 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)
|
switch (style)
|
||||||
{
|
{
|
||||||
@ -3501,7 +3498,7 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style,
|
|||||||
/* Compatible with ISO-8601 date formats */
|
/* Compatible with ISO-8601 date formats */
|
||||||
|
|
||||||
sprintf(str, "%04d-%02d-%02d %02d:%02d",
|
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);
|
tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -3514,18 +3511,18 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style,
|
|||||||
#ifdef HAVE_INT64_TIMESTAMP
|
#ifdef HAVE_INT64_TIMESTAMP
|
||||||
if (fsec != 0)
|
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);
|
TrimTrailingZeros(str);
|
||||||
}
|
}
|
||||||
#else
|
#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);
|
TrimTrailingZeros(str);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
else
|
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
|
* tzp == NULL indicates that we don't want *any* time zone
|
||||||
@ -3536,12 +3533,12 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style,
|
|||||||
if (tzp != NULL && tm->tm_isdst >= 0)
|
if (tzp != NULL && tm->tm_isdst >= 0)
|
||||||
{
|
{
|
||||||
hour = -(*tzp / 3600);
|
hour = -(*tzp / 3600);
|
||||||
min = ((abs(*tzp) / 60) % 60);
|
min = (abs(*tzp) / 60) % 60;
|
||||||
sprintf((str + strlen(str)), ((min != 0) ? "%+03d:%02d" : "%+03d"), hour, min);
|
sprintf(str + strlen(str), (min != 0) ? "%+03d:%02d" : "%+03d", hour, min);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tm->tm_year <= 0)
|
if (tm->tm_year <= 0)
|
||||||
sprintf((str + strlen(str)), " BC");
|
sprintf(str + strlen(str), " BC");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case USE_SQL_DATES:
|
case USE_SQL_DATES:
|
||||||
@ -3552,8 +3549,8 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style,
|
|||||||
else
|
else
|
||||||
sprintf(str, "%02d/%02d", tm->tm_mon, tm->tm_mday);
|
sprintf(str, "%02d/%02d", tm->tm_mon, tm->tm_mday);
|
||||||
|
|
||||||
sprintf((str + 5), "/%04d %02d:%02d",
|
sprintf(str + 5, "/%04d %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_hour, tm->tm_min);
|
tm->tm_hour, tm->tm_min);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -3566,33 +3563,33 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style,
|
|||||||
#ifdef HAVE_INT64_TIMESTAMP
|
#ifdef HAVE_INT64_TIMESTAMP
|
||||||
if (fsec != 0)
|
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);
|
TrimTrailingZeros(str);
|
||||||
}
|
}
|
||||||
#else
|
#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);
|
TrimTrailingZeros(str);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
else
|
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 (tzp != NULL && tm->tm_isdst >= 0)
|
||||||
{
|
{
|
||||||
if (*tzn != NULL)
|
if (*tzn != NULL)
|
||||||
sprintf((str + strlen(str)), " %.*s", MAXTZLEN, *tzn);
|
sprintf(str + strlen(str), " %.*s", MAXTZLEN, *tzn);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
hour = -(*tzp / 3600);
|
hour = -(*tzp / 3600);
|
||||||
min = ((abs(*tzp) / 60) % 60);
|
min = (abs(*tzp) / 60) % 60;
|
||||||
sprintf((str + strlen(str)), ((min != 0) ? "%+03d:%02d" : "%+03d"), hour, min);
|
sprintf(str + strlen(str), (min != 0) ? "%+03d:%02d" : "%+03d", hour, min);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tm->tm_year <= 0)
|
if (tm->tm_year <= 0)
|
||||||
sprintf((str + strlen(str)), " BC");
|
sprintf(str + strlen(str), " BC");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case USE_GERMAN_DATES:
|
case USE_GERMAN_DATES:
|
||||||
@ -3600,8 +3597,8 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style,
|
|||||||
|
|
||||||
sprintf(str, "%02d.%02d", tm->tm_mday, tm->tm_mon);
|
sprintf(str, "%02d.%02d", tm->tm_mday, tm->tm_mon);
|
||||||
|
|
||||||
sprintf((str + 5), ".%04d %02d:%02d",
|
sprintf(str + 5, ".%04d %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_hour, tm->tm_min);
|
tm->tm_hour, tm->tm_min);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -3614,33 +3611,33 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style,
|
|||||||
#ifdef HAVE_INT64_TIMESTAMP
|
#ifdef HAVE_INT64_TIMESTAMP
|
||||||
if (fsec != 0)
|
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);
|
TrimTrailingZeros(str);
|
||||||
}
|
}
|
||||||
#else
|
#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);
|
TrimTrailingZeros(str);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
else
|
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 (tzp != NULL && tm->tm_isdst >= 0)
|
||||||
{
|
{
|
||||||
if (*tzn != NULL)
|
if (*tzn != NULL)
|
||||||
sprintf((str + strlen(str)), " %.*s", MAXTZLEN, *tzn);
|
sprintf(str + strlen(str), " %.*s", MAXTZLEN, *tzn);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
hour = -(*tzp / 3600);
|
hour = -(*tzp / 3600);
|
||||||
min = ((abs(*tzp) / 60) % 60);
|
min = (abs(*tzp) / 60) % 60;
|
||||||
sprintf((str + strlen(str)), ((min != 0) ? "%+03d:%02d" : "%+03d"), hour, min);
|
sprintf(str + strlen(str), (min != 0) ? "%+03d:%02d" : "%+03d", hour, min);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tm->tm_year <= 0)
|
if (tm->tm_year <= 0)
|
||||||
sprintf((str + strlen(str)), " BC");
|
sprintf(str + strlen(str), " BC");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case USE_POSTGRES_DATES:
|
case USE_POSTGRES_DATES:
|
||||||
@ -3651,14 +3648,14 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style,
|
|||||||
tm->tm_wday = j2day(day);
|
tm->tm_wday = j2day(day);
|
||||||
|
|
||||||
strncpy(str, days[tm->tm_wday], 3);
|
strncpy(str, days[tm->tm_wday], 3);
|
||||||
strcpy((str + 3), " ");
|
strcpy(str + 3, " ");
|
||||||
|
|
||||||
if (DateOrder == DATEORDER_DMY)
|
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
|
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
|
* Print fractional seconds if any. The field widths here
|
||||||
@ -3670,26 +3667,26 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style,
|
|||||||
#ifdef HAVE_INT64_TIMESTAMP
|
#ifdef HAVE_INT64_TIMESTAMP
|
||||||
if (fsec != 0)
|
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);
|
TrimTrailingZeros(str);
|
||||||
}
|
}
|
||||||
#else
|
#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);
|
TrimTrailingZeros(str);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
else
|
else
|
||||||
sprintf((str + strlen(str)), ":%02d", tm->tm_sec);
|
sprintf(str + strlen(str), ":%02d", tm->tm_sec);
|
||||||
|
|
||||||
sprintf((str + strlen(str)), " %04d",
|
sprintf(str + strlen(str), " %04d",
|
||||||
((tm->tm_year > 0) ? tm->tm_year : -(tm->tm_year - 1)));
|
(tm->tm_year > 0) ? tm->tm_year : -(tm->tm_year - 1));
|
||||||
|
|
||||||
if (tzp != NULL && tm->tm_isdst >= 0)
|
if (tzp != NULL && tm->tm_isdst >= 0)
|
||||||
{
|
{
|
||||||
if (*tzn != NULL)
|
if (*tzn != NULL)
|
||||||
sprintf((str + strlen(str)), " %.*s", MAXTZLEN, *tzn);
|
sprintf(str + strlen(str), " %.*s", MAXTZLEN, *tzn);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
@ -3700,13 +3697,13 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style,
|
|||||||
* 2001-10-19
|
* 2001-10-19
|
||||||
*/
|
*/
|
||||||
hour = -(*tzp / 3600);
|
hour = -(*tzp / 3600);
|
||||||
min = ((abs(*tzp) / 60) % 60);
|
min = (abs(*tzp) / 60) % 60;
|
||||||
sprintf((str + strlen(str)), ((min != 0) ? " %+03d:%02d" : " %+03d"), hour, min);
|
sprintf(str + strlen(str), (min != 0) ? " %+03d:%02d" : " %+03d", hour, min);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tm->tm_year <= 0)
|
if (tm->tm_year <= 0)
|
||||||
sprintf((str + strlen(str)), " BC");
|
sprintf(str + strlen(str), " BC");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3742,7 +3739,7 @@ EncodeInterval(struct pg_tm * tm, fsec_t fsec, int style, char *str)
|
|||||||
if (tm->tm_year != 0)
|
if (tm->tm_year != 0)
|
||||||
{
|
{
|
||||||
sprintf(cp, "%d year%s",
|
sprintf(cp, "%d year%s",
|
||||||
tm->tm_year, ((tm->tm_year != 1) ? "s" : ""));
|
tm->tm_year, (tm->tm_year != 1) ? "s" : "");
|
||||||
cp += strlen(cp);
|
cp += strlen(cp);
|
||||||
is_before = (tm->tm_year < 0);
|
is_before = (tm->tm_year < 0);
|
||||||
is_nonzero = TRUE;
|
is_nonzero = TRUE;
|
||||||
@ -3750,9 +3747,9 @@ EncodeInterval(struct pg_tm * tm, fsec_t fsec, int style, char *str)
|
|||||||
|
|
||||||
if (tm->tm_mon != 0)
|
if (tm->tm_mon != 0)
|
||||||
{
|
{
|
||||||
sprintf(cp, "%s%s%d mon%s", (is_nonzero ? " " : ""),
|
sprintf(cp, "%s%s%d mon%s", is_nonzero ? " " : "",
|
||||||
((is_before && (tm->tm_mon > 0)) ? "+" : ""),
|
(is_before && tm->tm_mon > 0) ? "+" : "",
|
||||||
tm->tm_mon, ((tm->tm_mon != 1) ? "s" : ""));
|
tm->tm_mon, (tm->tm_mon != 1) ? "s" : "");
|
||||||
cp += strlen(cp);
|
cp += strlen(cp);
|
||||||
is_before = (tm->tm_mon < 0);
|
is_before = (tm->tm_mon < 0);
|
||||||
is_nonzero = TRUE;
|
is_nonzero = TRUE;
|
||||||
@ -3760,21 +3757,21 @@ EncodeInterval(struct pg_tm * tm, fsec_t fsec, int style, char *str)
|
|||||||
|
|
||||||
if (tm->tm_mday != 0)
|
if (tm->tm_mday != 0)
|
||||||
{
|
{
|
||||||
sprintf(cp, "%s%s%d day%s", (is_nonzero ? " " : ""),
|
sprintf(cp, "%s%s%d day%s", is_nonzero ? " " : "",
|
||||||
((is_before && (tm->tm_mday > 0)) ? "+" : ""),
|
(is_before && tm->tm_mday > 0) ? "+" : "",
|
||||||
tm->tm_mday, ((tm->tm_mday != 1) ? "s" : ""));
|
tm->tm_mday, (tm->tm_mday != 1) ? "s" : "");
|
||||||
cp += strlen(cp);
|
cp += strlen(cp);
|
||||||
is_before = (tm->tm_mday < 0);
|
is_before = (tm->tm_mday < 0);
|
||||||
is_nonzero = TRUE;
|
is_nonzero = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((!is_nonzero) || (tm->tm_hour != 0) || (tm->tm_min != 0)
|
if (!is_nonzero || tm->tm_hour != 0 || tm->tm_min != 0 ||
|
||||||
|| (tm->tm_sec != 0) || (fsec != 0))
|
tm->tm_sec != 0 || fsec != 0)
|
||||||
{
|
{
|
||||||
int minus = ((tm->tm_hour < 0) || (tm->tm_min < 0)
|
int minus = (tm->tm_hour < 0 || tm->tm_min < 0 ||
|
||||||
|| (tm->tm_sec < 0) || (fsec < 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 ? "+" : "")),
|
(minus ? "-" : (is_before ? "+" : "")),
|
||||||
abs(tm->tm_hour), abs(tm->tm_min));
|
abs(tm->tm_hour), abs(tm->tm_min));
|
||||||
cp += strlen(cp);
|
cp += strlen(cp);
|
||||||
@ -3816,7 +3813,7 @@ EncodeInterval(struct pg_tm * tm, fsec_t fsec, int style, char *str)
|
|||||||
year = -year;
|
year = -year;
|
||||||
|
|
||||||
sprintf(cp, "%d year%s", year,
|
sprintf(cp, "%d year%s", year,
|
||||||
((year != 1) ? "s" : ""));
|
(year != 1) ? "s" : "");
|
||||||
cp += strlen(cp);
|
cp += strlen(cp);
|
||||||
is_before = (tm->tm_year < 0);
|
is_before = (tm->tm_year < 0);
|
||||||
is_nonzero = TRUE;
|
is_nonzero = TRUE;
|
||||||
@ -3826,11 +3823,11 @@ EncodeInterval(struct pg_tm * tm, fsec_t fsec, int style, char *str)
|
|||||||
{
|
{
|
||||||
int mon = tm->tm_mon;
|
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;
|
mon = -mon;
|
||||||
|
|
||||||
sprintf(cp, "%s%d mon%s", (is_nonzero ? " " : ""), mon,
|
sprintf(cp, "%s%d mon%s", is_nonzero ? " " : "", mon,
|
||||||
((mon != 1) ? "s" : ""));
|
(mon != 1) ? "s" : "");
|
||||||
cp += strlen(cp);
|
cp += strlen(cp);
|
||||||
if (!is_nonzero)
|
if (!is_nonzero)
|
||||||
is_before = (tm->tm_mon < 0);
|
is_before = (tm->tm_mon < 0);
|
||||||
@ -3841,11 +3838,11 @@ EncodeInterval(struct pg_tm * tm, fsec_t fsec, int style, char *str)
|
|||||||
{
|
{
|
||||||
int day = tm->tm_mday;
|
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;
|
day = -day;
|
||||||
|
|
||||||
sprintf(cp, "%s%d day%s", (is_nonzero ? " " : ""), day,
|
sprintf(cp, "%s%d day%s", is_nonzero ? " " : "", day,
|
||||||
((day != 1) ? "s" : ""));
|
(day != 1) ? "s" : "");
|
||||||
cp += strlen(cp);
|
cp += strlen(cp);
|
||||||
if (!is_nonzero)
|
if (!is_nonzero)
|
||||||
is_before = (tm->tm_mday < 0);
|
is_before = (tm->tm_mday < 0);
|
||||||
@ -3855,11 +3852,11 @@ EncodeInterval(struct pg_tm * tm, fsec_t fsec, int style, char *str)
|
|||||||
{
|
{
|
||||||
int hour = tm->tm_hour;
|
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;
|
hour = -hour;
|
||||||
|
|
||||||
sprintf(cp, "%s%d hour%s", (is_nonzero ? " " : ""), hour,
|
sprintf(cp, "%s%d hour%s", is_nonzero ? " " : "", hour,
|
||||||
((hour != 1) ? "s" : ""));
|
(hour != 1) ? "s" : "");
|
||||||
cp += strlen(cp);
|
cp += strlen(cp);
|
||||||
if (!is_nonzero)
|
if (!is_nonzero)
|
||||||
is_before = (tm->tm_hour < 0);
|
is_before = (tm->tm_hour < 0);
|
||||||
@ -3870,11 +3867,11 @@ EncodeInterval(struct pg_tm * tm, fsec_t fsec, int style, char *str)
|
|||||||
{
|
{
|
||||||
int min = tm->tm_min;
|
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;
|
min = -min;
|
||||||
|
|
||||||
sprintf(cp, "%s%d min%s", (is_nonzero ? " " : ""), min,
|
sprintf(cp, "%s%d min%s", is_nonzero ? " " : "", min,
|
||||||
((min != 1) ? "s" : ""));
|
(min != 1) ? "s" : "");
|
||||||
cp += strlen(cp);
|
cp += strlen(cp);
|
||||||
if (!is_nonzero)
|
if (!is_nonzero)
|
||||||
is_before = (tm->tm_min < 0);
|
is_before = (tm->tm_min < 0);
|
||||||
@ -3888,27 +3885,27 @@ EncodeInterval(struct pg_tm * tm, fsec_t fsec, int style, char *str)
|
|||||||
|
|
||||||
#ifdef HAVE_INT64_TIMESTAMP
|
#ifdef HAVE_INT64_TIMESTAMP
|
||||||
sec = fsec;
|
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;
|
tm->tm_sec = -tm->tm_sec;
|
||||||
sec = -sec;
|
sec = -sec;
|
||||||
is_before = TRUE;
|
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;
|
sec = -sec;
|
||||||
is_before = TRUE;
|
is_before = TRUE;
|
||||||
}
|
}
|
||||||
sprintf(cp, "%s%d.%02d secs", (is_nonzero ? " " : ""),
|
sprintf(cp, "%s%d.%02d secs", is_nonzero ? " " : "",
|
||||||
tm->tm_sec, (((int) sec) / 10000));
|
tm->tm_sec, ((int) sec) / 10000);
|
||||||
cp += strlen(cp);
|
cp += strlen(cp);
|
||||||
#else
|
#else
|
||||||
fsec += tm->tm_sec;
|
fsec += tm->tm_sec;
|
||||||
sec = fsec;
|
sec = fsec;
|
||||||
if (is_before || ((!is_nonzero) && (fsec < 0)))
|
if (is_before || (!is_nonzero && fsec < 0))
|
||||||
sec = -sec;
|
sec = -sec;
|
||||||
|
|
||||||
sprintf(cp, "%s%.2f secs", (is_nonzero ? " " : ""), sec);
|
sprintf(cp, "%s%.2f secs", is_nonzero ? " " : "", sec);
|
||||||
cp += strlen(cp);
|
cp += strlen(cp);
|
||||||
if (!is_nonzero)
|
if (!is_nonzero)
|
||||||
is_before = (fsec < 0);
|
is_before = (fsec < 0);
|
||||||
@ -3920,11 +3917,11 @@ EncodeInterval(struct pg_tm * tm, fsec_t fsec, int style, char *str)
|
|||||||
{
|
{
|
||||||
int sec = tm->tm_sec;
|
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;
|
sec = -sec;
|
||||||
|
|
||||||
sprintf(cp, "%s%d sec%s", (is_nonzero ? " " : ""), sec,
|
sprintf(cp, "%s%d sec%s", is_nonzero ? " " : "", sec,
|
||||||
((sec != 1) ? "s" : ""));
|
(sec != 1) ? "s" : "");
|
||||||
cp += strlen(cp);
|
cp += strlen(cp);
|
||||||
if (!is_nonzero)
|
if (!is_nonzero)
|
||||||
is_before = (tm->tm_sec < 0);
|
is_before = (tm->tm_sec < 0);
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* 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 $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -264,7 +264,7 @@ AdjustTimestampForTypmod(Timestamp *time, int32 typmod)
|
|||||||
if (!TIMESTAMP_NOT_FINITE(*time)
|
if (!TIMESTAMP_NOT_FINITE(*time)
|
||||||
&& (typmod != -1) && (typmod != MAX_TIMESTAMP_PRECISION))
|
&& (typmod != -1) && (typmod != MAX_TIMESTAMP_PRECISION))
|
||||||
{
|
{
|
||||||
if ((typmod < 0) || (typmod > MAX_TIMESTAMP_PRECISION))
|
if (typmod < 0 || typmod > MAX_TIMESTAMP_PRECISION)
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||||
errmsg("timestamp(%d) precision must be between %d and %d",
|
errmsg("timestamp(%d) precision must be between %d and %d",
|
||||||
@ -578,12 +578,12 @@ interval_recv(PG_FUNCTION_ARGS)
|
|||||||
interval = (Interval *) palloc(sizeof(Interval));
|
interval = (Interval *) palloc(sizeof(Interval));
|
||||||
|
|
||||||
#ifdef HAVE_INT64_TIMESTAMP
|
#ifdef HAVE_INT64_TIMESTAMP
|
||||||
interval ->time = pq_getmsgint64(buf);
|
interval->time = pq_getmsgint64(buf);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
interval ->time = pq_getmsgfloat8(buf);
|
interval->time = pq_getmsgfloat8(buf);
|
||||||
#endif
|
#endif
|
||||||
interval ->month = pq_getmsgint(buf, sizeof(interval->month));
|
interval->month = pq_getmsgint(buf, sizeof(interval->month));
|
||||||
|
|
||||||
PG_RETURN_INTERVAL_P(interval);
|
PG_RETURN_INTERVAL_P(interval);
|
||||||
}
|
}
|
||||||
@ -678,28 +678,28 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod)
|
|||||||
}
|
}
|
||||||
else if (range == INTERVAL_MASK(YEAR))
|
else if (range == INTERVAL_MASK(YEAR))
|
||||||
{
|
{
|
||||||
interval ->month = ((interval->month / 12) *12);
|
interval->month = (interval->month / 12) * 12;
|
||||||
interval ->time = 0;
|
interval->time = 0;
|
||||||
}
|
}
|
||||||
else if (range == INTERVAL_MASK(MONTH))
|
else if (range == INTERVAL_MASK(MONTH))
|
||||||
{
|
{
|
||||||
interval ->month %= 12;
|
interval->month %= 12;
|
||||||
interval ->time = 0;
|
interval->time = 0;
|
||||||
}
|
}
|
||||||
/* YEAR TO MONTH */
|
/* YEAR TO MONTH */
|
||||||
else if (range == (INTERVAL_MASK(YEAR) | INTERVAL_MASK(MONTH)))
|
else if (range == (INTERVAL_MASK(YEAR) | INTERVAL_MASK(MONTH)))
|
||||||
interval ->time = 0;
|
interval->time = 0;
|
||||||
|
|
||||||
else if (range == INTERVAL_MASK(DAY))
|
else if (range == INTERVAL_MASK(DAY))
|
||||||
{
|
{
|
||||||
interval ->month = 0;
|
interval->month = 0;
|
||||||
|
|
||||||
#ifdef HAVE_INT64_TIMESTAMP
|
#ifdef HAVE_INT64_TIMESTAMP
|
||||||
interval ->time = (((int) (interval->time / INT64CONST(86400000000)))
|
interval->time = ((int) (interval->time / INT64CONST(86400000000))) *
|
||||||
* INT64CONST(86400000000));
|
INT64CONST(86400000000);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
interval ->time = (((int) (interval->time / 86400)) * 86400);
|
interval->time = ((int) (interval->time / 86400)) * 86400;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else if (range == INTERVAL_MASK(HOUR))
|
else if (range == INTERVAL_MASK(HOUR))
|
||||||
@ -711,17 +711,17 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod)
|
|||||||
double day;
|
double day;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
interval ->month = 0;
|
interval->month = 0;
|
||||||
|
|
||||||
#ifdef HAVE_INT64_TIMESTAMP
|
#ifdef HAVE_INT64_TIMESTAMP
|
||||||
day = (interval->time / INT64CONST(86400000000));
|
day = interval->time / INT64CONST(86400000000);
|
||||||
interval ->time -= (day * INT64CONST(86400000000));
|
interval->time -= day * INT64CONST(86400000000);
|
||||||
interval ->time = ((interval->time / INT64CONST(3600000000))
|
interval->time = (interval->time / INT64CONST(3600000000)) *
|
||||||
*INT64CONST(3600000000));
|
INT64CONST(3600000000);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
TMODULO(interval->time, day, 86400.0);
|
TMODULO(interval->time, day, 86400.0);
|
||||||
interval ->time = (((int) (interval->time / 3600)) * 3600.0);
|
interval->time = ((int) (interval->time / 3600)) * 3600.0;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else if (range == INTERVAL_MASK(MINUTE))
|
else if (range == INTERVAL_MASK(MINUTE))
|
||||||
@ -733,17 +733,17 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod)
|
|||||||
double hour;
|
double hour;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
interval ->month = 0;
|
interval->month = 0;
|
||||||
|
|
||||||
#ifdef HAVE_INT64_TIMESTAMP
|
#ifdef HAVE_INT64_TIMESTAMP
|
||||||
hour = (interval->time / INT64CONST(3600000000));
|
hour = interval->time / INT64CONST(3600000000);
|
||||||
interval ->time -= (hour * INT64CONST(3600000000));
|
interval->time -= hour * INT64CONST(3600000000);
|
||||||
interval ->time = ((interval->time / INT64CONST(60000000))
|
interval->time = (interval->time / INT64CONST(60000000)) *
|
||||||
*INT64CONST(60000000));
|
INT64CONST(60000000);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
TMODULO(interval->time, hour, 3600.0);
|
TMODULO(interval->time, hour, 3600.0);
|
||||||
interval ->time = (((int) (interval->time / 60)) * 60);
|
interval->time = ((int) (interval->time / 60)) * 60;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else if (range == INTERVAL_MASK(SECOND))
|
else if (range == INTERVAL_MASK(SECOND))
|
||||||
@ -755,11 +755,11 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod)
|
|||||||
double minute;
|
double minute;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
interval ->month = 0;
|
interval->month = 0;
|
||||||
|
|
||||||
#ifdef HAVE_INT64_TIMESTAMP
|
#ifdef HAVE_INT64_TIMESTAMP
|
||||||
minute = (interval->time / INT64CONST(60000000));
|
minute = interval->time / INT64CONST(60000000);
|
||||||
interval ->time -= (minute * INT64CONST(60000000));
|
interval->time -= minute * INT64CONST(60000000);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
TMODULO(interval->time, minute, 60.0);
|
TMODULO(interval->time, minute, 60.0);
|
||||||
@ -770,14 +770,14 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod)
|
|||||||
else if (range == (INTERVAL_MASK(DAY) |
|
else if (range == (INTERVAL_MASK(DAY) |
|
||||||
INTERVAL_MASK(HOUR)))
|
INTERVAL_MASK(HOUR)))
|
||||||
{
|
{
|
||||||
interval ->month = 0;
|
interval->month = 0;
|
||||||
|
|
||||||
#ifdef HAVE_INT64_TIMESTAMP
|
#ifdef HAVE_INT64_TIMESTAMP
|
||||||
interval ->time = ((interval->time / INT64CONST(3600000000))
|
interval->time = (interval->time / INT64CONST(3600000000)) *
|
||||||
*INT64CONST(3600000000));
|
INT64CONST(3600000000);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
interval ->time = (((int) (interval->time / 3600)) * 3600);
|
interval->time = ((int) (interval->time / 3600)) * 3600;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
/* DAY TO MINUTE */
|
/* DAY TO MINUTE */
|
||||||
@ -785,14 +785,14 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod)
|
|||||||
INTERVAL_MASK(HOUR) |
|
INTERVAL_MASK(HOUR) |
|
||||||
INTERVAL_MASK(MINUTE)))
|
INTERVAL_MASK(MINUTE)))
|
||||||
{
|
{
|
||||||
interval ->month = 0;
|
interval->month = 0;
|
||||||
|
|
||||||
#ifdef HAVE_INT64_TIMESTAMP
|
#ifdef HAVE_INT64_TIMESTAMP
|
||||||
interval ->time = ((interval->time / INT64CONST(60000000))
|
interval->time = (interval->time / INT64CONST(60000000)) *
|
||||||
*INT64CONST(60000000));
|
INT64CONST(60000000);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
interval ->time = (((int) (interval->time / 60)) * 60);
|
interval->time = ((int) (interval->time / 60)) * 60;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
/* DAY TO SECOND */
|
/* DAY TO SECOND */
|
||||||
@ -800,7 +800,7 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod)
|
|||||||
INTERVAL_MASK(HOUR) |
|
INTERVAL_MASK(HOUR) |
|
||||||
INTERVAL_MASK(MINUTE) |
|
INTERVAL_MASK(MINUTE) |
|
||||||
INTERVAL_MASK(SECOND)))
|
INTERVAL_MASK(SECOND)))
|
||||||
interval ->month = 0;
|
interval->month = 0;
|
||||||
|
|
||||||
/* HOUR TO MINUTE */
|
/* HOUR TO MINUTE */
|
||||||
else if (range == (INTERVAL_MASK(HOUR) |
|
else if (range == (INTERVAL_MASK(HOUR) |
|
||||||
@ -813,17 +813,17 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod)
|
|||||||
double day;
|
double day;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
interval ->month = 0;
|
interval->month = 0;
|
||||||
|
|
||||||
#ifdef HAVE_INT64_TIMESTAMP
|
#ifdef HAVE_INT64_TIMESTAMP
|
||||||
day = (interval->time / INT64CONST(86400000000));
|
day = (interval->time / INT64CONST(86400000000));
|
||||||
interval ->time -= (day * INT64CONST(86400000000));
|
interval->time -= day * INT64CONST(86400000000);
|
||||||
interval ->time = ((interval->time / INT64CONST(60000000))
|
interval->time = (interval->time / INT64CONST(60000000)) *
|
||||||
*INT64CONST(60000000));
|
INT64CONST(60000000);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
TMODULO(interval->time, day, 86400.0);
|
TMODULO(interval->time, day, 86400.0);
|
||||||
interval ->time = (((int) (interval->time / 60)) * 60);
|
interval->time = ((int) (interval->time / 60)) * 60;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
/* HOUR TO SECOND */
|
/* HOUR TO SECOND */
|
||||||
@ -838,11 +838,11 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod)
|
|||||||
double day;
|
double day;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
interval ->month = 0;
|
interval->month = 0;
|
||||||
|
|
||||||
#ifdef HAVE_INT64_TIMESTAMP
|
#ifdef HAVE_INT64_TIMESTAMP
|
||||||
day = (interval->time / INT64CONST(86400000000));
|
day = interval->time / INT64CONST(86400000000);
|
||||||
interval ->time -= (day * INT64CONST(86400000000));
|
interval->time -= day * INT64CONST(86400000000);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
TMODULO(interval->time, day, 86400.0);
|
TMODULO(interval->time, day, 86400.0);
|
||||||
@ -859,12 +859,11 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod)
|
|||||||
double hour;
|
double hour;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
interval ->month = 0;
|
interval->month = 0;
|
||||||
|
|
||||||
#ifdef HAVE_INT64_TIMESTAMP
|
#ifdef HAVE_INT64_TIMESTAMP
|
||||||
hour = (interval->time / INT64CONST(3600000000));
|
hour = interval->time / INT64CONST(3600000000);
|
||||||
interval ->time -= (hour * INT64CONST(3600000000));
|
interval->time -= hour * INT64CONST(3600000000);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
TMODULO(interval->time, hour, 3600.0);
|
TMODULO(interval->time, hour, 3600.0);
|
||||||
#endif
|
#endif
|
||||||
@ -875,7 +874,7 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod)
|
|||||||
/* Need to adjust precision? If not, don't even try! */
|
/* Need to adjust precision? If not, don't even try! */
|
||||||
if (precision != INTERVAL_FULL_PRECISION)
|
if (precision != INTERVAL_FULL_PRECISION)
|
||||||
{
|
{
|
||||||
if ((precision < 0) || (precision > MAX_INTERVAL_PRECISION))
|
if (precision < 0 || precision > MAX_INTERVAL_PRECISION)
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||||
errmsg("interval(%d) precision must be between %d and %d",
|
errmsg("interval(%d) precision must be between %d and %d",
|
||||||
@ -892,17 +891,22 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod)
|
|||||||
#ifdef HAVE_INT64_TIMESTAMP
|
#ifdef HAVE_INT64_TIMESTAMP
|
||||||
if (interval->time >= INT64CONST(0))
|
if (interval->time >= INT64CONST(0))
|
||||||
{
|
{
|
||||||
interval ->time = (((interval->time + IntervalOffsets[precision]) /IntervalScales[precision])
|
interval->time = (((interval->time +
|
||||||
* IntervalScales[precision]);
|
IntervalOffsets[precision]) /
|
||||||
|
IntervalScales[precision]) *
|
||||||
|
IntervalScales[precision];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
interval ->time = -(((-interval->time + IntervalOffsets[precision]) /IntervalScales[precision])
|
interval->time = -(((-interval->time +
|
||||||
* IntervalScales[precision]);
|
IntervalOffsets[precision]) /
|
||||||
|
IntervalScales[precision]) *
|
||||||
|
IntervalScales[precision]);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
interval ->time = (rint(((double) interval->time) *IntervalScales[precision])
|
interval->time = rint(((double) interval->time) *
|
||||||
/ IntervalScales[precision]);
|
IntervalScales[precision]) /
|
||||||
|
IntervalScales[precision];
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -954,17 +958,17 @@ dt2time(Timestamp jd, int *hour, int *min, int *sec, fsec_t *fsec)
|
|||||||
time = jd;
|
time = jd;
|
||||||
|
|
||||||
#ifdef HAVE_INT64_TIMESTAMP
|
#ifdef HAVE_INT64_TIMESTAMP
|
||||||
*hour = (time / INT64CONST(3600000000));
|
*hour = time / INT64CONST(3600000000);
|
||||||
time -= ((*hour) * INT64CONST(3600000000));
|
time -= (*hour) * INT64CONST(3600000000);
|
||||||
*min = (time / INT64CONST(60000000));
|
*min = time / INT64CONST(60000000);
|
||||||
time -= ((*min) * INT64CONST(60000000));
|
time -= (*min) * INT64CONST(60000000);
|
||||||
*sec = (time / INT64CONST(1000000));
|
*sec = time / INT64CONST(1000000);
|
||||||
*fsec = (time - (*sec * INT64CONST(1000000)));
|
*fsec = time - (*sec * INT64CONST(1000000));
|
||||||
#else
|
#else
|
||||||
*hour = (time / 3600);
|
*hour = time / 3600;
|
||||||
time -= ((*hour) * 3600);
|
time -= (*hour) * 3600;
|
||||||
*min = (time / 60);
|
*min = time / 60;
|
||||||
time -= ((*min) * 60);
|
time -= (*min) * 60;
|
||||||
*sec = time;
|
*sec = time;
|
||||||
*fsec = JROUND(time - *sec);
|
*fsec = JROUND(time - *sec);
|
||||||
#endif
|
#endif
|
||||||
@ -1010,7 +1014,7 @@ timestamp2tm(Timestamp dt, int *tzp, struct pg_tm * tm, fsec_t *fsec, char **tzn
|
|||||||
if (time < INT64CONST(0))
|
if (time < INT64CONST(0))
|
||||||
{
|
{
|
||||||
time += INT64CONST(86400000000);
|
time += INT64CONST(86400000000);
|
||||||
date -=1;
|
date -= 1;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
TMODULO(time, date, 86400e0);
|
TMODULO(time, date, 86400e0);
|
||||||
@ -1018,7 +1022,7 @@ timestamp2tm(Timestamp dt, int *tzp, struct pg_tm * tm, fsec_t *fsec, char **tzn
|
|||||||
if (time < 0)
|
if (time < 0)
|
||||||
{
|
{
|
||||||
time += 86400;
|
time += 86400;
|
||||||
date -=1;
|
date -=1;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -1138,15 +1142,16 @@ tm2timestamp(struct pg_tm * tm, fsec_t fsec, int *tzp, Timestamp *result)
|
|||||||
|
|
||||||
time = time2t(tm->tm_hour, tm->tm_min, tm->tm_sec, fsec);
|
time = time2t(tm->tm_hour, tm->tm_min, tm->tm_sec, fsec);
|
||||||
#ifdef HAVE_INT64_TIMESTAMP
|
#ifdef HAVE_INT64_TIMESTAMP
|
||||||
*result = (date *INT64CONST(86400000000)) +time;
|
*result = date * INT64CONST(86400000000) + time;
|
||||||
/* check for major overflow */
|
/* check for major overflow */
|
||||||
if ((*result - time) / INT64CONST(86400000000) != date)
|
if ((*result - time) / INT64CONST(86400000000) != date)
|
||||||
return -1;
|
return -1;
|
||||||
/* check for just-barely overflow (okay except time-of-day wraps) */
|
/* 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;
|
return -1;
|
||||||
#else
|
#else
|
||||||
*result = ((date *86400) +time);
|
*result = date * 86400 + time;
|
||||||
#endif
|
#endif
|
||||||
if (tzp != NULL)
|
if (tzp != NULL)
|
||||||
*result = dt2local(*result, -(*tzp));
|
*result = dt2local(*result, -(*tzp));
|
||||||
@ -1205,7 +1210,7 @@ interval2tm(Interval span, struct pg_tm * tm, fsec_t *fsec)
|
|||||||
int
|
int
|
||||||
tm2interval(struct pg_tm * tm, fsec_t fsec, Interval *span)
|
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
|
#ifdef HAVE_INT64_TIMESTAMP
|
||||||
span->time = ((((((((tm->tm_mday * INT64CONST(24))
|
span->time = ((((((((tm->tm_mday * INT64CONST(24))
|
||||||
+ tm->tm_hour) * INT64CONST(60))
|
+ tm->tm_hour) * INT64CONST(60))
|
||||||
@ -1611,14 +1616,14 @@ interval_cmp_internal(Interval *interval1, Interval *interval2)
|
|||||||
|
|
||||||
#ifdef HAVE_INT64_TIMESTAMP
|
#ifdef HAVE_INT64_TIMESTAMP
|
||||||
if (interval1->month != 0)
|
if (interval1->month != 0)
|
||||||
span1 += ((interval1->month * INT64CONST(30) * INT64CONST(86400000000)));
|
span1 += interval1->month * INT64CONST(30) * INT64CONST(86400000000);
|
||||||
if (interval2->month != 0)
|
if (interval2->month != 0)
|
||||||
span2 += ((interval2->month * INT64CONST(30) * INT64CONST(86400000000)));
|
span2 += interval2->month * INT64CONST(30) * INT64CONST(86400000000);
|
||||||
#else
|
#else
|
||||||
if (interval1->month != 0)
|
if (interval1->month != 0)
|
||||||
span1 += (interval1->month * (30.0 * 86400));
|
span1 += interval1->month * (30.0 * 86400);
|
||||||
if (interval2->month != 0)
|
if (interval2->month != 0)
|
||||||
span2 += (interval2->month * (30.0 * 86400));
|
span2 += interval2->month * (30.0 * 86400);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return ((span1 < span2) ? -1 : (span1 > span2) ? 1 : 0);
|
return ((span1 < span2) ? -1 : (span1 > span2) ? 1 : 0);
|
||||||
@ -2155,8 +2160,8 @@ interval_mul(PG_FUNCTION_ARGS)
|
|||||||
#ifdef HAVE_INT64_TIMESTAMP
|
#ifdef HAVE_INT64_TIMESTAMP
|
||||||
result->month = months;
|
result->month = months;
|
||||||
result->time = (span1->time * factor);
|
result->time = (span1->time * factor);
|
||||||
result->time += ((months - result->month) * INT64CONST(30)
|
result->time += (months - result->month) * INT64CONST(30) *
|
||||||
* INT64CONST(86400000000));
|
INT64CONST(86400000000);
|
||||||
#else
|
#else
|
||||||
result->month = rint(months);
|
result->month = rint(months);
|
||||||
result->time = JROUND(span1->time * factor);
|
result->time = JROUND(span1->time * factor);
|
||||||
@ -2199,10 +2204,10 @@ interval_div(PG_FUNCTION_ARGS)
|
|||||||
result->month = (span->month / factor);
|
result->month = (span->month / factor);
|
||||||
result->time = (span->time / factor);
|
result->time = (span->time / factor);
|
||||||
/* evaluate fractional months as 30 days */
|
/* evaluate fractional months as 30 days */
|
||||||
result->time += (((span->month - (result->month * factor))
|
result->time += ((span->month - (result->month * factor)) *
|
||||||
* INT64CONST(30) * INT64CONST(86400000000)) / factor);
|
INT64CONST(30) * INT64CONST(86400000000)) / factor;
|
||||||
#else
|
#else
|
||||||
months = (span->month / factor);
|
months = span->month / factor;
|
||||||
result->month = rint(months);
|
result->month = rint(months);
|
||||||
result->time = JROUND(span->time / factor);
|
result->time = JROUND(span->time / factor);
|
||||||
/* evaluate fractional months as 30 days */
|
/* evaluate fractional months as 30 days */
|
||||||
@ -2328,8 +2333,8 @@ timestamp_age(PG_FUNCTION_ARGS)
|
|||||||
|
|
||||||
result = (Interval *) palloc(sizeof(Interval));
|
result = (Interval *) palloc(sizeof(Interval));
|
||||||
|
|
||||||
if ((timestamp2tm(dt1, NULL, tm1, &fsec1, NULL) == 0)
|
if (timestamp2tm(dt1, NULL, tm1, &fsec1, NULL) == 0 &&
|
||||||
&& (timestamp2tm(dt2, NULL, tm2, &fsec2, NULL) == 0))
|
timestamp2tm(dt2, NULL, tm2, &fsec2, NULL) == 0)
|
||||||
{
|
{
|
||||||
fsec = (fsec1 - fsec2);
|
fsec = (fsec1 - fsec2);
|
||||||
tm->tm_sec = (tm1->tm_sec - tm2->tm_sec);
|
tm->tm_sec = (tm1->tm_sec - tm2->tm_sec);
|
||||||
@ -2442,8 +2447,8 @@ timestamptz_age(PG_FUNCTION_ARGS)
|
|||||||
|
|
||||||
result = (Interval *) palloc(sizeof(Interval));
|
result = (Interval *) palloc(sizeof(Interval));
|
||||||
|
|
||||||
if ((timestamp2tm(dt1, &tz1, tm1, &fsec1, &tzn) == 0)
|
if (timestamp2tm(dt1, &tz1, tm1, &fsec1, &tzn) == 0 &&
|
||||||
&& (timestamp2tm(dt2, &tz2, tm2, &fsec2, &tzn) == 0))
|
timestamp2tm(dt2, &tz2, tm2, &fsec2, &tzn) == 0)
|
||||||
{
|
{
|
||||||
fsec = (fsec1 - fsec2);
|
fsec = (fsec1 - fsec2);
|
||||||
tm->tm_sec = (tm1->tm_sec - tm2->tm_sec);
|
tm->tm_sec = (tm1->tm_sec - tm2->tm_sec);
|
||||||
@ -2810,7 +2815,7 @@ timestamp_trunc(PG_FUNCTION_ARGS)
|
|||||||
|
|
||||||
case DTK_MILLISEC:
|
case DTK_MILLISEC:
|
||||||
#ifdef HAVE_INT64_TIMESTAMP
|
#ifdef HAVE_INT64_TIMESTAMP
|
||||||
fsec = ((fsec / 1000) * 1000);
|
fsec = (fsec / 1000) * 1000;
|
||||||
#else
|
#else
|
||||||
fsec = rint(fsec * 1000) / 1000;
|
fsec = rint(fsec * 1000) / 1000;
|
||||||
#endif
|
#endif
|
||||||
@ -3150,7 +3155,7 @@ date2isoweek(int year, int mon, int mday)
|
|||||||
* We need the first week containing a Thursday, otherwise this day
|
* We need the first week containing a Thursday, otherwise this day
|
||||||
* falls into the previous year for purposes of counting weeks
|
* falls into the previous year for purposes of counting weeks
|
||||||
*/
|
*/
|
||||||
if (dayn < (day4 - day0))
|
if (dayn < day4 - day0)
|
||||||
{
|
{
|
||||||
day4 = date2j(year - 1, 1, 4);
|
day4 = date2j(year - 1, 1, 4);
|
||||||
|
|
||||||
@ -3158,7 +3163,7 @@ date2isoweek(int year, int mon, int mday)
|
|||||||
day0 = j2day(day4 - 1);
|
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
|
* Sometimes the last few days in a year will fall into the first week
|
||||||
@ -3171,8 +3176,8 @@ date2isoweek(int year, int mon, int mday)
|
|||||||
/* day0 == offset to first day of week (Monday) */
|
/* day0 == offset to first day of week (Monday) */
|
||||||
day0 = j2day(day4 - 1);
|
day0 = j2day(day4 - 1);
|
||||||
|
|
||||||
if (dayn >= (day4 - day0))
|
if (dayn >= day4 - day0)
|
||||||
result = (((dayn - (day4 - day0)) / 7) + 1);
|
result = (dayn - (day4 - day0)) / 7 + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (int) result;
|
return (int) result;
|
||||||
@ -3204,7 +3209,7 @@ date2isoyear(int year, int mon, int mday)
|
|||||||
* We need the first week containing a Thursday, otherwise this day
|
* We need the first week containing a Thursday, otherwise this day
|
||||||
* falls into the previous year for purposes of counting weeks
|
* falls into the previous year for purposes of counting weeks
|
||||||
*/
|
*/
|
||||||
if (dayn < (day4 - day0))
|
if (dayn < day4 - day0)
|
||||||
{
|
{
|
||||||
day4 = date2j(year - 1, 1, 4);
|
day4 = date2j(year - 1, 1, 4);
|
||||||
|
|
||||||
@ -3214,7 +3219,7 @@ date2isoyear(int year, int mon, int mday)
|
|||||||
year--;
|
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
|
* Sometimes the last few days in a year will fall into the first week
|
||||||
@ -3227,7 +3232,7 @@ date2isoyear(int year, int mon, int mday)
|
|||||||
/* day0 == offset to first day of week (Monday) */
|
/* day0 == offset to first day of week (Monday) */
|
||||||
day0 = j2day(day4 - 1);
|
day0 = j2day(day4 - 1);
|
||||||
|
|
||||||
if (dayn >= (day4 - day0))
|
if (dayn >= day4 - day0)
|
||||||
year++;
|
year++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3276,7 +3281,7 @@ timestamp_part(PG_FUNCTION_ARGS)
|
|||||||
{
|
{
|
||||||
case DTK_MICROSEC:
|
case DTK_MICROSEC:
|
||||||
#ifdef HAVE_INT64_TIMESTAMP
|
#ifdef HAVE_INT64_TIMESTAMP
|
||||||
result = ((tm->tm_sec * 1000000e0) + fsec);
|
result = tm->tm_sec * 1000000e0 + fsec;
|
||||||
#else
|
#else
|
||||||
result = (tm->tm_sec + fsec) * 1000000;
|
result = (tm->tm_sec + fsec) * 1000000;
|
||||||
#endif
|
#endif
|
||||||
@ -3284,7 +3289,7 @@ timestamp_part(PG_FUNCTION_ARGS)
|
|||||||
|
|
||||||
case DTK_MILLISEC:
|
case DTK_MILLISEC:
|
||||||
#ifdef HAVE_INT64_TIMESTAMP
|
#ifdef HAVE_INT64_TIMESTAMP
|
||||||
result = ((tm->tm_sec * 1000e0) + (fsec / 1000e0));
|
result = tm->tm_sec * 1000e0 + fsec / 1000e0;
|
||||||
#else
|
#else
|
||||||
result = (tm->tm_sec + fsec) * 1000;
|
result = (tm->tm_sec + fsec) * 1000;
|
||||||
#endif
|
#endif
|
||||||
@ -3292,9 +3297,9 @@ timestamp_part(PG_FUNCTION_ARGS)
|
|||||||
|
|
||||||
case DTK_SECOND:
|
case DTK_SECOND:
|
||||||
#ifdef HAVE_INT64_TIMESTAMP
|
#ifdef HAVE_INT64_TIMESTAMP
|
||||||
result = (tm->tm_sec + (fsec / 1000000e0));
|
result = tm->tm_sec + fsec / 1000000e0;
|
||||||
#else
|
#else
|
||||||
result = (tm->tm_sec + fsec);
|
result = tm->tm_sec + fsec;
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -3315,7 +3320,7 @@ timestamp_part(PG_FUNCTION_ARGS)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case DTK_QUARTER:
|
case DTK_QUARTER:
|
||||||
result = ((tm->tm_mon - 1) / 3) + 1;
|
result = (tm->tm_mon - 1) / 3 + 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DTK_WEEK:
|
case DTK_WEEK:
|
||||||
@ -3345,10 +3350,11 @@ timestamp_part(PG_FUNCTION_ARGS)
|
|||||||
|
|
||||||
case DTK_CENTURY:
|
case DTK_CENTURY:
|
||||||
|
|
||||||
/*
|
/* ----
|
||||||
* centuries AD, c>0: year in [ (c-1)*100+1 : c*100 ]
|
* centuries AD, c>0: year in [ (c-1)* 100 + 1 : c*100 ]
|
||||||
* centuries BC, c<0: year in [ c*100 : (c+1)*100-1
|
* centuries BC, c<0: year in [ c*100 : (c+1) * 100 - 1]
|
||||||
* ] there is no number 0 century.
|
* there is no number 0 century.
|
||||||
|
* ----
|
||||||
*/
|
*/
|
||||||
if (tm->tm_year > 0)
|
if (tm->tm_year > 0)
|
||||||
result = ((tm->tm_year + 99) / 100);
|
result = ((tm->tm_year + 99) / 100);
|
||||||
@ -3368,11 +3374,11 @@ timestamp_part(PG_FUNCTION_ARGS)
|
|||||||
case DTK_JULIAN:
|
case DTK_JULIAN:
|
||||||
result = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday);
|
result = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday);
|
||||||
#ifdef HAVE_INT64_TIMESTAMP
|
#ifdef HAVE_INT64_TIMESTAMP
|
||||||
result += (((((tm->tm_hour * 60) + tm->tm_min) * 60)
|
result += ((((tm->tm_hour * 60) + tm->tm_min) * 60) +
|
||||||
+ tm->tm_sec + (fsec / 1000000e0)) / 86400e0);
|
tm->tm_sec + (fsec / 1000000e0)) / 86400e0;
|
||||||
#else
|
#else
|
||||||
result += (((((tm->tm_hour * 60) + tm->tm_min) * 60)
|
result += ((((tm->tm_hour * 60) + tm->tm_min) * 60) +
|
||||||
+ tm->tm_sec + fsec) / 86400e0);
|
tm->tm_sec + fsec) / 86400e0;
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -3515,7 +3521,7 @@ timestamptz_part(PG_FUNCTION_ARGS)
|
|||||||
|
|
||||||
case DTK_MICROSEC:
|
case DTK_MICROSEC:
|
||||||
#ifdef HAVE_INT64_TIMESTAMP
|
#ifdef HAVE_INT64_TIMESTAMP
|
||||||
result = ((tm->tm_sec * 1000000e0) + fsec);
|
result = tm->tm_sec * 1000000e0 + fsec;
|
||||||
#else
|
#else
|
||||||
result = (tm->tm_sec + fsec) * 1000000;
|
result = (tm->tm_sec + fsec) * 1000000;
|
||||||
#endif
|
#endif
|
||||||
@ -3523,7 +3529,7 @@ timestamptz_part(PG_FUNCTION_ARGS)
|
|||||||
|
|
||||||
case DTK_MILLISEC:
|
case DTK_MILLISEC:
|
||||||
#ifdef HAVE_INT64_TIMESTAMP
|
#ifdef HAVE_INT64_TIMESTAMP
|
||||||
result = ((tm->tm_sec * 1000e0) + (fsec / 1000e0));
|
result = tm->tm_sec * 1000e0 + fsec / 1000e0;
|
||||||
#else
|
#else
|
||||||
result = (tm->tm_sec + fsec) * 1000;
|
result = (tm->tm_sec + fsec) * 1000;
|
||||||
#endif
|
#endif
|
||||||
@ -3531,9 +3537,9 @@ timestamptz_part(PG_FUNCTION_ARGS)
|
|||||||
|
|
||||||
case DTK_SECOND:
|
case DTK_SECOND:
|
||||||
#ifdef HAVE_INT64_TIMESTAMP
|
#ifdef HAVE_INT64_TIMESTAMP
|
||||||
result = (tm->tm_sec + (fsec / 1000000e0));
|
result = tm->tm_sec + fsec / 1000000e0;
|
||||||
#else
|
#else
|
||||||
result = (tm->tm_sec + fsec);
|
result = tm->tm_sec + fsec;
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -3554,7 +3560,7 @@ timestamptz_part(PG_FUNCTION_ARGS)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case DTK_QUARTER:
|
case DTK_QUARTER:
|
||||||
result = ((tm->tm_mon - 1) / 3) + 1;
|
result = (tm->tm_mon - 1) / 3 + 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DTK_WEEK:
|
case DTK_WEEK:
|
||||||
@ -3580,7 +3586,7 @@ timestamptz_part(PG_FUNCTION_ARGS)
|
|||||||
case DTK_CENTURY:
|
case DTK_CENTURY:
|
||||||
/* see comments in timestamp_part */
|
/* see comments in timestamp_part */
|
||||||
if (tm->tm_year > 0)
|
if (tm->tm_year > 0)
|
||||||
result = ((tm->tm_year + 99) / 100);
|
result = (tm->tm_year + 99) / 100;
|
||||||
else
|
else
|
||||||
result = -((99 - (tm->tm_year - 1)) / 100);
|
result = -((99 - (tm->tm_year - 1)) / 100);
|
||||||
break;
|
break;
|
||||||
@ -3588,7 +3594,7 @@ timestamptz_part(PG_FUNCTION_ARGS)
|
|||||||
case DTK_MILLENNIUM:
|
case DTK_MILLENNIUM:
|
||||||
/* see comments in timestamp_part */
|
/* see comments in timestamp_part */
|
||||||
if (tm->tm_year > 0)
|
if (tm->tm_year > 0)
|
||||||
result = ((tm->tm_year + 999) / 1000);
|
result = (tm->tm_year + 999) / 1000;
|
||||||
else
|
else
|
||||||
result = -((999 - (tm->tm_year - 1)) / 1000);
|
result = -((999 - (tm->tm_year - 1)) / 1000);
|
||||||
break;
|
break;
|
||||||
@ -3596,11 +3602,11 @@ timestamptz_part(PG_FUNCTION_ARGS)
|
|||||||
case DTK_JULIAN:
|
case DTK_JULIAN:
|
||||||
result = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday);
|
result = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday);
|
||||||
#ifdef HAVE_INT64_TIMESTAMP
|
#ifdef HAVE_INT64_TIMESTAMP
|
||||||
result += (((((tm->tm_hour * 60) + tm->tm_min) * 60)
|
result += ((((tm->tm_hour * 60) + tm->tm_min) * 60) +
|
||||||
+ tm->tm_sec + (fsec / 1000000e0)) / 86400e0);
|
tm->tm_sec + (fsec / 1000000e0)) / 86400e0;
|
||||||
#else
|
#else
|
||||||
result += (((((tm->tm_hour * 60) + tm->tm_min) * 60)
|
result += ((((tm->tm_hour * 60) + tm->tm_min) * 60) +
|
||||||
+ tm->tm_sec + fsec) / 86400e0);
|
tm->tm_sec + fsec) / 86400e0;
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -3619,9 +3625,9 @@ timestamptz_part(PG_FUNCTION_ARGS)
|
|||||||
{
|
{
|
||||||
case DTK_EPOCH:
|
case DTK_EPOCH:
|
||||||
#ifdef HAVE_INT64_TIMESTAMP
|
#ifdef HAVE_INT64_TIMESTAMP
|
||||||
result = ((timestamp -SetEpochTimestamp()) /1000000e0);
|
result = (timestamp - SetEpochTimestamp()) /1000000e0;
|
||||||
#else
|
#else
|
||||||
result = timestamp -SetEpochTimestamp();
|
result = timestamp - SetEpochTimestamp();
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -3696,7 +3702,7 @@ interval_part(PG_FUNCTION_ARGS)
|
|||||||
{
|
{
|
||||||
case DTK_MICROSEC:
|
case DTK_MICROSEC:
|
||||||
#ifdef HAVE_INT64_TIMESTAMP
|
#ifdef HAVE_INT64_TIMESTAMP
|
||||||
result = ((tm->tm_sec * 1000000e0) + fsec);
|
result = tm->tm_sec * 1000000e0 + fsec;
|
||||||
#else
|
#else
|
||||||
result = (tm->tm_sec + fsec) * 1000000;
|
result = (tm->tm_sec + fsec) * 1000000;
|
||||||
#endif
|
#endif
|
||||||
@ -3704,7 +3710,7 @@ interval_part(PG_FUNCTION_ARGS)
|
|||||||
|
|
||||||
case DTK_MILLISEC:
|
case DTK_MILLISEC:
|
||||||
#ifdef HAVE_INT64_TIMESTAMP
|
#ifdef HAVE_INT64_TIMESTAMP
|
||||||
result = ((tm->tm_sec * 1000e0) + (fsec / 1000e0));
|
result = tm->tm_sec * 1000e0 + fsec / 1000e0;
|
||||||
#else
|
#else
|
||||||
result = (tm->tm_sec + fsec) * 1000;
|
result = (tm->tm_sec + fsec) * 1000;
|
||||||
#endif
|
#endif
|
||||||
@ -3712,9 +3718,9 @@ interval_part(PG_FUNCTION_ARGS)
|
|||||||
|
|
||||||
case DTK_SECOND:
|
case DTK_SECOND:
|
||||||
#ifdef HAVE_INT64_TIMESTAMP
|
#ifdef HAVE_INT64_TIMESTAMP
|
||||||
result = (tm->tm_sec + (fsec / 1000000e0));
|
result = tm->tm_sec + fsec / 1000000e0;
|
||||||
#else
|
#else
|
||||||
result = (tm->tm_sec + fsec);
|
result = tm->tm_sec + fsec;
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -3773,17 +3779,17 @@ interval_part(PG_FUNCTION_ARGS)
|
|||||||
result = 0;
|
result = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ((type == RESERV) && (val == DTK_EPOCH))
|
else if (type == RESERV && val == DTK_EPOCH)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_INT64_TIMESTAMP
|
#ifdef HAVE_INT64_TIMESTAMP
|
||||||
result = (interval->time / 1000000e0);
|
result = interval->time / 1000000e0;
|
||||||
#else
|
#else
|
||||||
result = interval->time;
|
result = interval->time;
|
||||||
#endif
|
#endif
|
||||||
if (interval->month != 0)
|
if (interval->month != 0)
|
||||||
{
|
{
|
||||||
result += ((365.25 * 86400) * (interval->month / 12));
|
result += (365.25 * 86400) * (interval->month / 12);
|
||||||
result += ((30.0 * 86400) * (interval->month % 12));
|
result += (30.0 * 86400) * (interval->month % 12);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -3825,7 +3831,7 @@ timestamp_zone(PG_FUNCTION_ARGS)
|
|||||||
|
|
||||||
type = DecodeSpecial(0, lowzone, &val);
|
type = DecodeSpecial(0, lowzone, &val);
|
||||||
|
|
||||||
if ((type == TZ) || (type == DTZ))
|
if (type == TZ || type == DTZ)
|
||||||
{
|
{
|
||||||
tz = -(val * 60);
|
tz = -(val * 60);
|
||||||
|
|
||||||
@ -3866,9 +3872,9 @@ timestamp_izone(PG_FUNCTION_ARGS)
|
|||||||
PointerGetDatum(zone))))));
|
PointerGetDatum(zone))))));
|
||||||
|
|
||||||
#ifdef HAVE_INT64_TIMESTAMP
|
#ifdef HAVE_INT64_TIMESTAMP
|
||||||
tz = (zone->time / INT64CONST(1000000));
|
tz = zone->time / INT64CONST(1000000);
|
||||||
#else
|
#else
|
||||||
tz = (zone->time);
|
tz = zone->time;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
result = dt2local(timestamp, tz);
|
result = dt2local(timestamp, tz);
|
||||||
@ -3974,7 +3980,7 @@ timestamptz_zone(PG_FUNCTION_ARGS)
|
|||||||
|
|
||||||
type = DecodeSpecial(0, lowzone, &val);
|
type = DecodeSpecial(0, lowzone, &val);
|
||||||
|
|
||||||
if ((type == TZ) || (type == DTZ))
|
if (type == TZ || type == DTZ)
|
||||||
{
|
{
|
||||||
tz = val * 60;
|
tz = val * 60;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user