mi,
ss,
ssss,
- d,
+ d, /* stored as 1-7, Sunday = 1, 0 means missing */
dd,
ddd,
mm,
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:
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);
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:
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)
/* 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);
}
extern int isoweek2j(int year, int week);
extern void isoweek2date(int woy, int *year, int *mon, int *mday);
-extern void isoweekdate2date(int isoweek, int isowday, int *year, int *mon, int *mday);
+extern void isoweekdate2date(int isoweek, int wday, int *year, int *mon, int *mday);
extern int date2isoweek(int year, int mon, int mday);
extern int date2isoyear(int year, int mon, int mday);
extern int date2isoyearday(int year, int mon, int mday);