/usr/share/octave/packages/3.2/time-1.0.9/thirdwednesday.m is in octave-time 1.0.9-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | ## Copyright (C) 2008 Bill Denney
##
## This software is free software; you can redistribute it and/or modify it
## under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 3 of the License, or (at
## your option) any later version.
##
## This software is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this software; see the file COPYING. If not, see
## <http://www.gnu.org/licenses/>.
## -*- texinfo -*-
## @deftypefn {Function File} {[begindate, enddate]} = thirdwednesday (month, year)
##
## Find the third Wednesday of the month specified by the @var{month}
## and @var{year}. The @var{begindate} is the third Wednesday of the
## month, and the @var{enddate} is three months after that. Outputs are
## in the form of datenums.
##
## The third Wednesday is used for Eurodollar futures.
##
## @seealso{nweekdate, datenum}
## @end deftypefn
## Author: Bill Denney <bill@denney.ws>
## Created: 24 Feb 2008
function [wednesdays, enddate] = thirdwednesday (month, year)
if nargin ~= 2
print_usage ();
elseif ~ ((numel(year) == 1) ||
(numel(month) == 1) ||
~isequal (size (month), size (year)))
error("month and year must have the same size or one of them must be a scalar")
endif
if numel (year) == 1
sz = size (month);
else
sz = size (year);
endif
wednesdays = nweekdate (3, 4, year, month);
dates = datevec (wednesdays);
## adjust the year when the date will wrap
dates(:,1) += dates (:,2) > 9;
## adjust the month by three
dates(:,2) = mod (dates(:,2) + 2, 12) + 1;
enddate = reshape (datenum (dates), sz);
endfunction
## Tests
%!shared m, y, bt, et
%! m = (1:12)';
%! y = 2008;
%! bt = datenum(2008, m, [16;20;19;16;21;18;16;20;17;15;19;17]);
%! et = datenum([2008*ones(9,1);2009*ones(3,1)], [4:12 1:3]', [16;20;19;16;21;18;16;20;17;15;19;17]);
%!test
%! [b e] = thirdwednesday (m, y);
%! assert(b, bt)
%! assert(e, et)
%!test
%! [b e] = thirdwednesday (m', y);
%! assert(b, bt')
%! assert(e, et')
|