Allow daysinmon() to take a single DATE or DATETIME argument.

This commit is contained in:
Dianne Skoll
2025-07-02 10:14:48 -04:00
parent 1af2bdf8f1
commit 4fd145cf4e
4 changed files with 41 additions and 8 deletions

View File

@@ -3467,8 +3467,10 @@ 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)
.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.
.TP
.B defined(s_var)
Returns 1 if the variable named by \fIvar\fR is defined, or 0 if it is not.

View File

@@ -267,7 +267,7 @@ BuiltinFunc Func[] = {
{ "datetime", 2, 5, 1, FDateTime, NULL },
{ "dawn", 0, 1, 0, FDawn, NULL },
{ "day", 1, 1, 1, FDay, NULL },
{ "daysinmon", 2, 2, 1, FDaysinmon, NULL },
{ "daysinmon", 1, 2, 1, FDaysinmon, NULL },
{ "defined", 1, 1, 0, FDefined, NULL },
{ "dosubst", 1, 3, 0, FDosubst, NULL },
{ "dusk", 0, 1, 0, FDusk, NULL },
@@ -2008,19 +2008,30 @@ static int FTrigdatetime(func_info *info)
/* */
/* FDaysinmon */
/* */
/* Returns the number of days in mon,yr */
/* Returns the number of days in mon,yr OR month containing */
/* given date. */
/* */
/***************************************************************/
static int FDaysinmon(func_info *info)
{
if (ARG(0).type != INT_TYPE || ARG(1).type != INT_TYPE) return E_BAD_TYPE;
int y, m;
if (ARGV(0) > 12 || ARGV(0) < 1 ||
ARGV(1) < BASE || ARGV(1) > BASE+YR_RANGE)
return E_DOMAIN_ERR;
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 (ARGV(0) > 12 || ARGV(0) < 1 ||
ARGV(1) < BASE || ARGV(1) > BASE+YR_RANGE) {
return E_DOMAIN_ERR;
}
m = ARGV(0) - 1;
y = ARGV(1);
}
RetVal.type = INT_TYPE;
RETVAL = DaysInMonth(ARGV(0)-1, ARGV(1));
RETVAL = DaysInMonth(m, y);
return OK;
}

View File

@@ -16579,6 +16579,14 @@ Base: 1991-02-09
../tests/test.rem(1612): Expired
trigvalid = 1; trigdate = 1991-01-14
trigvalid = 0; trigdate = 0
daysinmon(2, 2000) => 29
daysinmon(2, 2001) => 28
daysinmon(3, 2000) => 31
daysinmon(3, 2001) => 31
daysinmon(2000-02-14) => 29
daysinmon(2001-02-14) => 28
daysinmon(2000-04-14) => 30
daysinmon(2001-04-14) => 30
Variable hash table statistics:
Entries: 100143; Buckets: 87719; Non-empty Buckets: 66301
Maxlen: 5; Minlen: 0; Avglen: 1.142; Stddev: 0.878; Avg nonempty len: 1.510

View File

@@ -1626,6 +1626,18 @@ set b trigdate()
REM MSG trigvalid = [a]; trigdate = [b]
DEBUG +x
set a daysinmon(2, 2000)
set a daysinmon(2, 2001)
set a daysinmon(3, 2000)
set a daysinmon(3, 2001)
set a daysinmon('2000-02-14')
set a daysinmon('2001-02-14')
set a daysinmon('2000-04-14')
set a daysinmon('2001-04-14')
DEBUG -x
# Output expression-node stats
DEBUG +h