diff --git a/man/remind.1.in b/man/remind.1.in index b7fbe63b..96a7a601 100644 --- a/man/remind.1.in +++ b/man/remind.1.in @@ -4536,9 +4536,13 @@ representing the day of the week of the date. If \fIarg\fR is an \fBINT\fR from 0 to 6, returns the corresponding weekday ("Sunday" to "Saturday"). .TP -.B wkdaynum(dq_date) -Returns a number from 0 to 6 representing the day-of-week of the specified -\fIdate\fR. (0 represents Sunday, and 6 represents Saturday.) +.B wkdaynum(dq_date)\fR or \fBwkdaynum(s_str)\fR +Returns a number from 0 to 6 representing the day-of-week of the +specified \fIdate\fR. (0 represents Sunday, and 6 represents +Saturday.) If a \fBSTRING\fR is supplied, then if \fIstr\fR is a valid +weekday name (or minimum 3-character abbreviation thereof) then the +corresponding weekday number is returned. If \fIstr\fR is not a valid +weekday name, then an error occurs. .TP .B year(dq_date) Returns a \fBINT\fR that is the year component of \fIdate\fR. diff --git a/src/funcs.c b/src/funcs.c index 459250d6..d05536e9 100644 --- a/src/funcs.c +++ b/src/funcs.c @@ -775,6 +775,17 @@ static int FYear(func_info *info) static int FWkdaynum(func_info *info) { int v; + Token tok; + if (ARG(0).type == STR_TYPE) { + /* Convert a day name to a day number */ + FindToken(ARG(0).v.str, &tok); + if (tok.type != T_WkDay) { + return E_BAD_TYPE; + } + RetVal.type = INT_TYPE; + RETVAL = (tok.val + 1) % 7; + return OK; + } if (!HASDATE(ARG(0))) return E_BAD_TYPE; v = DATEPART(ARG(0)); diff --git a/tests/test.cmp b/tests/test.cmp index b06f3125..8bab43b9 100644 --- a/tests/test.cmp +++ b/tests/test.cmp @@ -16355,6 +16355,41 @@ set a monnum("not a month") monnum("not a month") => Type mismatch ../tests/test.rem(1483): monnum(): Type mismatch +# Test wkdaynum("string") +set a wkdaynum("Sun") +wkdaynum("Sun") => 0 +set a wkdaynum("Mon") +wkdaynum("Mon") => 1 +set a wkdaynum("Tue") +wkdaynum("Tue") => 2 +set a wkdaynum("Wed") +wkdaynum("Wed") => 3 +set a wkdaynum("Thu") +wkdaynum("Thu") => 4 +set a wkdaynum("FRI") +wkdaynum("FRI") => 5 +set a wkdaynum("sat") +wkdaynum("sat") => 6 + +set a wkdaynum("Sunday") +wkdaynum("Sunday") => 0 +set a wkdaynum("Monday") +wkdaynum("Monday") => 1 +set a wkdaynum("Tuesday") +wkdaynum("Tuesday") => 2 +set a wkdaynum("Wednesday") +wkdaynum("Wednesday") => 3 +set a wkdaynum("Thursday") +wkdaynum("Thursday") => 4 +set a wkdaynum("FRIDAY") +wkdaynum("FRIDAY") => 5 +set a wkdaynum("saturday") +wkdaynum("saturday") => 6 + +set a wkdaynum("cabbage") +wkdaynum("cabbage") => Type mismatch +../tests/test.rem(1502): wkdaynum(): Type mismatch + DEBUG -x DEBUG -e Variable hash table statistics: diff --git a/tests/test.rem b/tests/test.rem index f949678e..e22860be 100644 --- a/tests/test.rem +++ b/tests/test.rem @@ -1482,6 +1482,25 @@ set a monnum("Dec") set a monnum("not a month") +# Test wkdaynum("string") +set a wkdaynum("Sun") +set a wkdaynum("Mon") +set a wkdaynum("Tue") +set a wkdaynum("Wed") +set a wkdaynum("Thu") +set a wkdaynum("FRI") +set a wkdaynum("sat") + +set a wkdaynum("Sunday") +set a wkdaynum("Monday") +set a wkdaynum("Tuesday") +set a wkdaynum("Wednesday") +set a wkdaynum("Thursday") +set a wkdaynum("FRIDAY") +set a wkdaynum("saturday") + +set a wkdaynum("cabbage") + DEBUG -x DEBUG -e