Allow first argument of daysinmon to be a string.

This commit is contained in:
Dianne Skoll
2025-07-02 11:20:15 -04:00
parent 4fd145cf4e
commit 8356dacf2a
4 changed files with 29 additions and 9 deletions

View File

@@ -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.

View File

@@ -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);
}

View File

@@ -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

View File

@@ -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')