function [hr, min, sec, isAM] = fromSeconds(seconds)
%FROMSECONDS Seconds after midnight to 24-hour time
%  [hr, min, sec, isAM] = fromSeconds(seconds) returns
%  the 12-hour clock time hr:min:sec given a
%  number of seconds after midnight. isAM is equal
%  to true if the time is before noon and is equal 
%  to false if the time is noon or after noon.
%
%  seconds is expected to be greater than 0 but may
%  be greater than the number of seconds in one day

% wrap seconds to number of seconds in one day
SEC_PER_MIN = 60;
SEC_PER_HOUR = SEC_PER_MIN * 60;
SEC_PER_DAY = SEC_PER_HOUR * 24;
seconds = mod(seconds, SEC_PER_DAY);

% the hour on a 24-hour clock
hr24 = floor(seconds / SEC_PER_HOUR);

% the minute
seconds = seconds - SEC_PER_HOUR * hr24;
min = floor(seconds / SEC_PER_MIN);

% the second
sec = seconds - SEC_PER_MIN * min;

% convert hr24 to 12-hour time
if hr24 < 12
    hr = hr24;
    if hr == 0
        hr = 12;
    end
    isAM = true;
else
    hr = hr24 - 12;
    if hr == 0
        hr = 12;
    end
    isAM = false;
end
