1## Copyright (C) 2008 Bill Denney <bill@denney.ws> 2## Copyright (C) 2013 Carnë Draug <carandraug@octave.org> 3## 4## This program is free software; you can redistribute it and/or modify it under 5## the terms of the GNU General Public License as published by the Free Software 6## Foundation; either version 3 of the License, or (at your option) any later 7## version. 8## 9## This program is distributed in the hope that it will be useful, but WITHOUT 10## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 12## details. 13## 14## You should have received a copy of the GNU General Public License along with 15## this program; if not, see <http://www.gnu.org/licenses/>. 16 17## -*- texinfo -*- 18## @deftypefn {Function File} {[@var{num}, @var{str}] =} month (@var{date}) 19## @deftypefnx {Function File} {[@dots{}] =} month (@var{date}, @var{f}) 20## Return month of a date. 21## 22## For a given @var{date} in a serial date number or date string format, 23## returns its month number (@var{num}) or 3 letter name (@var{str}). 24## 25## The optional variable @var{f}, specifies the format string used to 26## interpret date strings. 27## 28## @seealso{date, datevec, now, day, year} 29## @end deftypefn 30 31function [num, str] = month (varargin) 32 33 if (nargin < 1 || nargin > 2) 34 print_usage (); 35 elseif (nargin >= 2 && ! ischar (varargin{2})) 36 error ("month: F must be a string"); 37 endif 38 39 num = datevec (varargin{:})(:,2); 40 str = datestr ([0 num 0 0 0 0], "mmm"); 41 42endfunction 43 44%!assert (nthargout (1:2, @month, 523383), {12 "Dec"}); 45%!assert (nthargout (1:2, @month, "12-02-34", "mm-dd-yy"), {12 "Dec"}); 46 47