diff options
author | Bruce Momjian <bruce@momjian.us> | 2012-09-03 22:52:34 -0400 |
---|---|---|
committer | Bruce Momjian <bruce@momjian.us> | 2012-09-03 22:52:44 -0400 |
commit | 015722fb364416b29fb1bb2c10631feb67ad61cd (patch) | |
tree | dfeaba3901788d298d2b122f3d2aa6eb18fa8071 /src/backend/utils/adt/timestamp.c | |
parent | e442b0f0c6fd26738bafdeb5222511b586dfe4b9 (diff) | |
download | postgresql-015722fb364416b29fb1bb2c10631feb67ad61cd.tar.gz postgresql-015722fb364416b29fb1bb2c10631feb67ad61cd.zip |
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
Diffstat (limited to 'src/backend/utils/adt/timestamp.c')
-rw-r--r-- | src/backend/utils/adt/timestamp.c | 12 |
1 files changed, 8 insertions, 4 deletions
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); } |