Home > atmlab > time > isdate.m

isdate

PURPOSE ^

ISDATE True for valid dates (Gregorian calendar).

SYNOPSIS ^

function t = isdate(varargin)

DESCRIPTION ^

ISDATE True for valid dates (Gregorian calendar).

   ISDATE(YEAR, MONTH, DAY) returns 1 if input is a valid year-month-date
   triple and 0 otherwise.  Gregorian calendar is assumed.

   See also ISJDATE.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

isdate.m

SOURCE CODE ^

0001 function t = isdate(varargin)
0002 %ISDATE True for valid dates (Gregorian calendar).
0003 %
0004 %   ISDATE(YEAR, MONTH, DAY) returns 1 if input is a valid year-month-date
0005 %   triple and 0 otherwise.  Gregorian calendar is assumed.
0006 %
0007 %   See also ISJDATE.
0008 
0009 %   Author:      Peter J. Acklam
0010 %   Time-stamp:  2002-03-03 12:51:49 +0100
0011 %   E-mail:      pjacklam@online.no
0012 %   URL:         http://home.online.no/~pjacklam
0013 
0014    nargsin = nargin;
0015    error(nargchk(1, 3, nargsin));
0016    argv = {1 1 1};
0017    argv(1:nargsin) = varargin;
0018    [year, month, day] = deal(argv{:});
0019 
0020    t =   ~imag(year) & ~imag(month) & ~imag(day) ...
0021        & (year == round(year)) & (month == round(month)) ...
0022        & (day == round(day)) & (1 <= month) & (month <= 12) & (1 <= day);
0023 
0024    % Since this function might be called at the beginning of other
0025    % time-related m-files, we make this function independent of all other
0026    % m-files to avoid infinite recursion.
0027 
0028    days = [ 31 28 31 30 31 30 31 31 30 31 30 31 ];
0029    is_february = month == 2;
0030    is_leapyear = ( ~rem(year, 4) & rem(year, 100) ) | ~rem(year, 400);
0031    days_in_month = days(month) + ( is_february & is_leapyear );
0032 
0033    t = t & ( day <= days_in_month );

Generated on Mon 15-Sep-2014 13:31:28 by m2html © 2005