1 ## Copyright (C) 1996-2012 John W. Eaton
3 ## This file is part of Octave.
5 ## Octave is free software; you can redistribute it and/or modify it
6 ## under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation; either version 3 of the License, or (at
8 ## your option) any later version.
10 ## Octave is distributed in the hope that it will be useful, but
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ## General Public License for more details.
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING. If not, see
17 ## <http://www.gnu.org/licenses/>.
20 ## @deftypefn {Function File} {} is_leap_year ()
21 ## @deftypefnx {Function File} {} is_leap_year (@var{year})
22 ## Return true if @var{year} is a leap year and false otherwise. If no
23 ## year is specified, @code{is_leap_year} uses the current year.
28 ## is_leap_year (2000)
32 ## @seealso{weekday, eomday, calendar}
37 function retval = is_leap_year (year)
48 retval = (rem (year, 4) == 0 & rem (year, 100) != 0) | (rem (year, 400) == 0);
53 %!assert (is_leap_year (2000), true)
54 %!assert (is_leap_year (1976), true)
55 %!assert (is_leap_year (1000), false)
56 %!assert (is_leap_year (1800), false)
57 %!assert (is_leap_year (1600), true)
59 %!error is_leap_year (1, 2);