mirror of
https://github.com/postgres/postgres.git
synced 2025-06-16 06:01:02 +03:00
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
This commit is contained in:
@ -412,7 +412,7 @@ typedef struct
|
||||
mi,
|
||||
ss,
|
||||
ssss,
|
||||
d,
|
||||
d, /* stored as 1-7, Sunday = 1, 0 means missing */
|
||||
dd,
|
||||
ddd,
|
||||
mm,
|
||||
@ -2897,6 +2897,7 @@ DCH_from_char(FormatNode *node, char *in, TmFromChar *out)
|
||||
from_char_seq_search(&value, &s, days, ONE_UPPER,
|
||||
MAX_DAY_LEN, n);
|
||||
from_char_set_int(&out->d, value, n);
|
||||
out->d++;
|
||||
break;
|
||||
case DCH_DY:
|
||||
case DCH_Dy:
|
||||
@ -2904,6 +2905,7 @@ DCH_from_char(FormatNode *node, char *in, TmFromChar *out)
|
||||
from_char_seq_search(&value, &s, days, ONE_UPPER,
|
||||
MAX_DY_LEN, n);
|
||||
from_char_set_int(&out->d, value, n);
|
||||
out->d++;
|
||||
break;
|
||||
case DCH_DDD:
|
||||
from_char_parse_int(&out->ddd, &s, n);
|
||||
@ -2919,11 +2921,13 @@ DCH_from_char(FormatNode *node, char *in, TmFromChar *out)
|
||||
break;
|
||||
case DCH_D:
|
||||
from_char_parse_int(&out->d, &s, n);
|
||||
out->d--;
|
||||
s += SKIP_THth(n->suffix);
|
||||
break;
|
||||
case DCH_ID:
|
||||
from_char_parse_int_len(&out->d, &s, 1, n);
|
||||
/* Shift numbering to match Gregorian where Sunday = 1 */
|
||||
if (++out->d > 7)
|
||||
out->d = 1;
|
||||
s += SKIP_THth(n->suffix);
|
||||
break;
|
||||
case DCH_WW:
|
||||
@ -3534,7 +3538,7 @@ do_to_timestamp(text *date_txt, text *fmt,
|
||||
if (tmfc.w)
|
||||
tmfc.dd = (tmfc.w - 1) * 7 + 1;
|
||||
if (tmfc.d)
|
||||
tm->tm_wday = tmfc.d;
|
||||
tm->tm_wday = tmfc.d - 1; /* convert to native numbering */
|
||||
if (tmfc.dd)
|
||||
tm->tm_mday = tmfc.dd;
|
||||
if (tmfc.ddd)
|
||||
|
Reference in New Issue
Block a user