1 ## Copyright (C) 2008 Bill Denney <bill@denney.ws>
3 ## This program is free software; you can redistribute it and/or modify it under
4 ## the terms of the GNU General Public License as published by the Free Software
5 ## Foundation; either version 3 of the License, or (at your option) any later
8 ## This program is distributed in the hope that it will be useful, but WITHOUT
9 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 ## You should have received a copy of the GNU General Public License along with
14 ## this program; if not, see <http://www.gnu.org/licenses/>.
17 ## @deftypefn {Function File} {r =} isbusday (refdate)
18 ## @deftypefnx {Function File} {r =} isbusday (refdate, holiday)
19 ## @deftypefnx {Function File} {r =} isbusday (refdate, holiday, weekend)
21 ## Return true if the @var{refdate} is a business date @var{refdate}.
22 ## @var{holiday} is a vector of datenums that defines the holidays
23 ## observed (the holidays function is used if not given). @var{weekend}
24 ## defines the days of the week that should be considered weekends;
25 ## [1 0 0 0 0 0 1] (default) indicates that Sunday and Saturday are
28 ## @seealso{holidays, lbusdate, busdate, fbusdate}
31 function mask = isbusday (rd, hol=[], wkend=[])
37 ## Get all possible holidays that could affect the output.
38 hol = holidays (min(rd), max(rd));
41 wkend = [1 0 0 0 0 0 1];
42 elseif numel (wkend) ~= 7
43 error ("wkend must have 7 elements")
48 mask = reshape (wkend (weekday (rd)), size (rd));
51 mask = mask | ismember(rd, hol);
58 %!assert(isbusday(datenum(2008,1,2)), true())
60 %!assert(isbusday(datenum(2008,1,1)), false())
61 %!assert(isbusday(datenum(2008,1,1), []), false())
63 %!assert(isbusday(datenum(2008,2,2)), false())
64 ## An alternate holiday
65 %!assert(isbusday(datenum(2008,1,2), datenum(2008,1,2)), false())
66 ## An alternate weekend
67 %!assert(isbusday(datenum(2008,1,2), [], zeros(1,7)), true())
68 %!assert(isbusday(datenum(2008,1,2), [], ones(1,7)), false())
70 %!assert(isbusday([datenum(2008,1,2) datenum(2008,2,2)]), [true() false()])
71 ## A vector in the other direction
72 %!assert(isbusday([datenum(2008,1,2);datenum(2008,2,2)]), [true();false()])