1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-13 07:41:39 +03:00

Fix interval input parser so that fractional weeks and months are

cascaded first to days and only what is leftover into seconds.  This
seems to satisfy the principle of least surprise given the general
conversion to three-part interval values --- it was an oversight that
these cases weren't dealt with in 8.1.  Michael Glaesemann
This commit is contained in:
Tom Lane
2006-09-04 01:26:28 +00:00
parent 091fe03775
commit 57bfb27e60
4 changed files with 72 additions and 30 deletions

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.169 2006/07/25 03:51:21 tgl Exp $
* $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.170 2006/09/04 01:26:27 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -2920,16 +2920,23 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct pg_tm * tm,
tm->tm_mday += val * 7;
if (fval != 0)
{
int sec;
fval *= 7 * SECS_PER_DAY;
sec = fval;
tm->tm_sec += sec;
int extra_days;
fval *= 7;
extra_days = (int32) fval;
tm->tm_mday += extra_days;
fval -= extra_days;
if (fval != 0)
{
int sec;
fval *= 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);
break;
@ -2938,16 +2945,23 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct pg_tm * tm,
tm->tm_mon += val;
if (fval != 0)
{
int sec;
fval *= DAYS_PER_MONTH * SECS_PER_DAY;
sec = fval;
tm->tm_sec += sec;
int day;
fval *= DAYS_PER_MONTH;
day = fval;
tm->tm_mday += day;
fval -= day;
if (fval != 0)
{
int sec;
fval *= 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);
break;