function [month,day] = astHelperDayCheck(year,month,day)
% ASTHELPERDAYCHECK This helper function supports the Celestial Navigation
% Example. It checks for out of bounds day specifications such as April
% 31st. Do not use it directly. 

% Copyright 2013 The MathWorks, Inc.

switch month
    %January, March, May, July, August, October, December
    case {1,3,5,7,8,10,12}
        if (day > 31)
            month = month + 1;
            day = day - 31;
        end
    %February
    case {2}
        % Check for leap year
        if leapyear(year)
            if (day > 29)
                month = month + 1;
                day = day - 29;
            end
        else
            if day > 28
                month = month + 1;
                day = day - 28;
            end
        end
    %April, June, September, November
    case {4,6,9,11}
        if day > 30
            month = month + 1;
            day = day - 30;            
        end
end

% EOF