Home > atmlab > time > istime.m

istime

PURPOSE ^

ISTIME True for valid times.

SYNOPSIS ^

function t = istime(varargin)

DESCRIPTION ^

ISTIME True for valid times.

   ISTIME(HOUR, MINUTE, SECOND) returns 1 if input is a valid
   hour-minute-second triple and 0 otherwise.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

istime.m

SOURCE CODE ^

0001 function t = istime(varargin)
0002 %ISTIME True for valid times.
0003 %
0004 %   ISTIME(HOUR, MINUTE, SECOND) returns 1 if input is a valid
0005 %   hour-minute-second triple and 0 otherwise.
0006 
0007 %   Author:      Peter J. Acklam
0008 %   Time-stamp:  2002-03-03 12:51:42 +0100
0009 %   E-mail:      pjacklam@online.no
0010 %   URL:         http://home.online.no/~pjacklam
0011 
0012    nargsin = nargin;
0013    error(nargchk(1, 3, nargsin));
0014    argv = {0 0 0};
0015    argv(1:nargsin) = varargin;
0016    [hour, minute, second] = deal(argv{:});
0017 
0018    % Hour is an integer, 0 <= hour <= 24.  Minute is an integer, 0 <= minute
0019    % < 60, with one exception: when hour is 24, minute must be 0.  Second is
0020    % a real number, 0 <= second < 60, with two exceptions: firstly, when
0021    % hour is 24, second must be 0; secondly, when hour is 23 and minute is
0022    % 59, second may be 0 <= second < 61 (to allow for positive leap
0023    % seconds).  A positive leap second is introduced by letting the last
0024    % minute of the last hour (of the last day of the month) have 61 seconds.
0025    % I.e., 23:59:60 <= leap second < 23:59:61 = 00:00:00 the following day.
0026 
0027    t =   ~imag(hour) & ~imag(minute) & ~imag(second)     ...  % real
0028        & hour == round(hour) & minute == round(minute)   ...  % integers
0029        & 0 <= hour & 0 <= minute & 0 <= second           ...  % positive
0030        & (   ( hour <= 23 & minute <= 59 & second < 60 ) ...  % most times
0031            | ( hour == 23 & minute == 59 & second < 61 ) ...  % allow leap sec
0032            | ( hour == 24 & minute ==  0 & second == 0 ) ...  % midnight
0033          );

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