From 015722fb364416b29fb1bb2c10631feb67ad61cd Mon Sep 17 00:00:00 2001 From: Bruce Momjian Date: Mon, 3 Sep 2012 22:52:34 -0400 Subject: Fix to_date() and to_timestamp() to allow specification of the day of the week via ISO or Gregorian designations. The fix is to store the day-of-week consistently as 1-7, Sunday = 1. Fixes bug reported by Marc Munro --- src/backend/utils/adt/timestamp.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/backend/utils/adt/timestamp.c') diff --git a/src/backend/utils/adt/timestamp.c b/src/backend/utils/adt/timestamp.c index 2adc178de4f..50ef8976bed 100644 --- a/src/backend/utils/adt/timestamp.c +++ b/src/backend/utils/adt/timestamp.c @@ -3775,18 +3775,22 @@ isoweek2date(int woy, int *year, int *mon, int *mday) /* isoweekdate2date() * - * Convert an ISO 8601 week date (ISO year, ISO week and day of week) into a Gregorian date. + * Convert an ISO 8601 week date (ISO year, ISO week) into a Gregorian date. + * Gregorian day of week sent so weekday strings can be supplied. * Populates year, mon, and mday with the correct Gregorian values. * year must be passed in as the ISO year. */ void -isoweekdate2date(int isoweek, int isowday, int *year, int *mon, int *mday) +isoweekdate2date(int isoweek, int wday, int *year, int *mon, int *mday) { int jday; jday = isoweek2j(*year, isoweek); - jday += isowday - 1; - + /* convert Gregorian week start (Sunday=1) to ISO week start (Monday=1) */ + if (wday > 1) + jday += wday - 2; + else + jday += 6; j2date(jday, year, mon, mday); } -- cgit v1.2.3