diff --git a/man/remind.1.in b/man/remind.1.in index f6644780..f4202290 100644 --- a/man/remind.1.in +++ b/man/remind.1.in @@ -3467,10 +3467,12 @@ This function takes a \fBDATE\fR or \fBDATETIME\fR as an argument, and returns an \fBINT\fR that is the day-of-month component of \fIdate\fR. .TP -.B daysinmon(i_m, i_y)\fR or \fB daysinmon(dq_date)\fR -Returns the number of days in month \fIm\fR (1-12) of the year \fIy\fR. -If given a DATE or DATETIME argument, returns the number of days in -the month containing the argument. +.B daysinmon(si_m, i_y)\fR or \fB daysinmon(dq_date)\fR +Returns the number of days in month \fIm\fR (1-12) of the year +\fIy\fR. The first argument can either be an integer from 1 to 12, or +a string that is the name of a month. If given a single DATE or +DATETIME argument, returns the number of days in the month containing +the argument. .TP .B defined(s_var) Returns 1 if the variable named by \fIvar\fR is defined, or 0 if it is not. diff --git a/src/funcs.c b/src/funcs.c index db989348..6ff99573 100644 --- a/src/funcs.c +++ b/src/funcs.c @@ -2015,18 +2015,27 @@ static int FTrigdatetime(func_info *info) static int FDaysinmon(func_info *info) { int y, m; + Token tok; if (Nargs == 1) { if (!HASDATE(ARG(0))) return E_BAD_TYPE; FromDSE(DATEPART(ARG(0)), &y, &m, NULL); } else { - if (ARG(0).type != INT_TYPE || ARG(1).type != INT_TYPE) return E_BAD_TYPE; + if ((ARG(0).type != INT_TYPE && ARG(0).type != STR_TYPE) || ARG(1).type != INT_TYPE) return E_BAD_TYPE; - if (ARGV(0) > 12 || ARGV(0) < 1 || - ARGV(1) < BASE || ARGV(1) > BASE+YR_RANGE) { - return E_DOMAIN_ERR; + if (ARG(0).type == STR_TYPE) { + FindToken(ARG(0).v.str, &tok); + if (tok.type != T_Month) { + return E_BAD_TYPE; + } + m = tok.val; + } else { + if (ARGV(0) > 12 || ARGV(0) < 1 || + ARGV(1) < BASE || ARGV(1) > BASE+YR_RANGE) { + return E_DOMAIN_ERR; + } + m = ARGV(0) - 1; } - m = ARGV(0) - 1; y = ARGV(1); } diff --git a/tests/test.cmp b/tests/test.cmp index ffdf6800..b46b0ca2 100644 --- a/tests/test.cmp +++ b/tests/test.cmp @@ -16583,6 +16583,10 @@ daysinmon(2, 2000) => 29 daysinmon(2, 2001) => 28 daysinmon(3, 2000) => 31 daysinmon(3, 2001) => 31 +daysinmon("Feb", 2000) => 29 +daysinmon("Feb", 2001) => 28 +daysinmon("March", 2000) => 31 +daysinmon("March", 2001) => 31 daysinmon(2000-02-14) => 29 daysinmon(2001-02-14) => 28 daysinmon(2000-04-14) => 30 diff --git a/tests/test.rem b/tests/test.rem index 0993f0e2..02c368eb 100644 --- a/tests/test.rem +++ b/tests/test.rem @@ -1632,6 +1632,11 @@ set a daysinmon(2, 2001) set a daysinmon(3, 2000) set a daysinmon(3, 2001) +set a daysinmon("Feb", 2000) +set a daysinmon("Feb", 2001) +set a daysinmon("March", 2000) +set a daysinmon("March", 2001) + set a daysinmon('2000-02-14') set a daysinmon('2001-02-14') set a daysinmon('2000-04-14')