Updates to nomomitted:

o Add optional "step" argument
  o If start > end, swap the first two arguments
  o Update man page and tests
This commit is contained in:
Dianne Skoll
2023-07-14 19:31:05 -04:00
parent 34bb250ba3
commit 1baa6dab0c
4 changed files with 796 additions and 12 deletions

View File

@@ -3266,14 +3266,31 @@ is supplied, only the date component is used.
Returns the time of "nautical twilight" on the specified \fIdate\fR. If
\fIdate\fR is omitted, defaults to \fBtoday()\fR.
.TP
.B nonomitted(dq_start, dq_end [,s_wkday...])
.B nonomitted(dq_start, dq_end [, i_step] [,s_wkday...])
This function returns the number of \fInon-\fRomitted days between
\fIstart\fR and \fIend\fR. If \fIstart\fR is non-omitted, then it is
counted. \fIend\fR is never counted.
.RS
.PP
Note that \fIend\fR must be greater than or equal to \fIstart\fR or an
error is reported. In addition to using the global OMIT context, you
Note that if \fIend\fR is less than \ffIstart\fR, the arguments
are effectively swapped, so counting always begins from the older
date.
.PP
If the third argument to \fBnonomitted\fR is an \fBINT\fR, then it must
be greater than zero, and is consider to be the \fIstep\fR by which
\fBnonomitted\fR counts. For example the following expression:
.PP
.nf
nonomitted('2023-07-01', '2023-07-29', 7)
.fi
.PP
returns the number of non-omitted Saturdays from 2023-07-01 up to
(but not including) 2023-07-29. (Both 2023-07-01 and 2023-07-29 are
Saturdays.)
.PP
If no \fIstep\fR argument is supplied, then a step of 1 is used.
.PP
In addition to using the global OMIT context, you
can supply additional arguments that are names of weekdays to be
omitted. However, in a \fBREM\fR command, any local \fBOMITFUNC\fR
clause is \fInot\fR taken into account by this function.

View File

@@ -3335,6 +3335,8 @@ FNonomitted(func_info *info)
{
int d1, d2, ans, localomit, i;
int omit, r;
int step = 1;
int localargs = 2;
Token tok;
if (!HASDATE(ARG(0)) ||
@@ -3343,10 +3345,20 @@ FNonomitted(func_info *info)
}
d1 = DATEPART(ARG(0));
d2 = DATEPART(ARG(1));
if (d2 < d1) return E_2LOW;
if (d2 < d1) {
i = d1;
d1 = d2;
d2 = i;
}
/* Check for a "step" argument - it's an INT */
if (Nargs > 2 && ARG(2).type == INT_TYPE) {
step = ARGV(2);
if (step < 1) return E_2LOW;
localargs++;
}
localomit = 0;
for (i=2; i<Nargs; i++) {
for (i=localargs; i<Nargs; i++) {
if (ARG(i).type != STR_TYPE) return E_BAD_TYPE;
FindToken(ARG(i).v.str, &tok);
if (tok.type != T_WkDay) return E_UNKNOWN_TOKEN;
@@ -3355,11 +3367,12 @@ FNonomitted(func_info *info)
ans = 0;
while (d1 < d2) {
r = IsOmitted(d1++, localomit, NULL, &omit);
r = IsOmitted(d1, localomit, NULL, &omit);
if (r) return r;
if (!omit) {
ans++;
}
d1 += step;
}
RetVal.type = INT_TYPE;
RETVAL = ans;

File diff suppressed because it is too large Load Diff

View File

@@ -26,6 +26,16 @@ REM 12 AUG SPECIAL MOON 0
# Test nonomitted
REM MSG [nonomitted('2007-08-01', today())] NonOmit-1
REM MSG [nonomitted('2007-08-01', today(), "Sat", "Sun")] NonOmit-2
REM MSG [nonomitted('2007-08-01', '2007-08-30', 7)]
REM MSG [nonomitted('2007-08-01', '2007-08-29', 7)]
REM MSG [nonomitted('2007-08-28', '2007-08-01', 7)]
PUSH-OMIT-CONTEXT
OMIT 2007-08-15
REM MSG [nonomitted('2007-08-01', '2007-08-30', 7)]
REM MSG [nonomitted('2007-08-01', '2007-08-29', 7)]
REM MSG [nonomitted('2007-08-01', '2007-08-28', 7)]
POP-OMIT-CONTEXT
# Test SPECIAL COLOR with an AT clause
REM 20 AUG AT 13:45 SPECIAL COLOR 6 7 8 Mooo!