function [flag, Value]=IsTimeFormat(h,numberFormat,rawData)
% ISTIMEFORMAT check time format of a single cell

% input parameters should be in Cell Array format
% output:   between 0~31: standard MATLAB supported date/time format
%           -1: double values
%           NaN: string or other cases

% Author: Rong Chen 
% Revised: 
% Copyright 1986-2004 The MathWorks, Inc.


% get value from cell
numberFormat=cell2mat(numberFormat);
rawData=cell2mat(rawData);
Value=rawData;
% check if date/time format
if isnumeric(rawData) && ~isnan(rawData)
    % it can be a double or a time format
    if ~isempty(strfind(numberFormat,':'))
        % a time format identified
        % get matlab corresponding format number if there is a match
        if strcmp(numberFormat,'h:mm:ss') || strcmp(numberFormat,'h:mm:ss;@') || ...
           strcmp(numberFormat,'[$-409]h:mm:ss') || strcmp(numberFormat,'[$-409]h:mm:ss;@') || ...
           strcmp(numberFormat,'[$-F400]h:mm:ss') || strcmp(numberFormat,'[$-F400]h:mm:ss;@')
            flag=13;
            return
        elseif strcmp(numberFormat,'h:mm:ss AM/PM') || strcmp(numberFormat,'h:mm:ss AM/PM;@') || ...
               strcmp(numberFormat,'[$-409]h:mm:ss AM/PM') || strcmp(numberFormat,'[$-409]h:mm:ss AM/PM;@') || ...
               strcmp(numberFormat,'[$-F400]h:mm:ss AM/PM') || strcmp(numberFormat,'[$-F400]h:mm:ss AM/PM;@')
            flag=14;
            return
        elseif strcmp(numberFormat,'h:mm') || strcmp(numberFormat,'h:mm;@') || ...
               strcmp(numberFormat,'[$-409]h:mm') || strcmp(numberFormat,'[$-409]h:mm;@') || ...
               strcmp(numberFormat,'[$-F400]h:mm') || strcmp(numberFormat,'[$-F400]h:mm;@')
            flag=15;
            return
        elseif strcmp(numberFormat,'h:mm AM/PM') || strcmp(numberFormat,'h:mm AM/PM;@') || ...
               strcmp(numberFormat,'[$-409]h:mm AM/PM') || strcmp(numberFormat,'[$-409]h:mm AM/PM;@') || ...
               strcmp(numberFormat,'[$-F400]h:mm AM/PM') || strcmp(numberFormat,'[$-F400]h:mm AM/PM;@')
            flag=16;            
            return
        else
            % for other cases, use the default matlab time format 13 
            flag=13;
            return
        end
    else
        % not an absolute date/time format
        flag=-1;
        return
    end
end
if ischar(rawData)
    % it can be any string or a date format
%     if ~isfield(h.Handles,'COMBdataSample')
        try 
            Value=datenum(rawData);
        catch
            % not an absolute date/time format
            flag=NaN;
            return
        end
%     else
%         if get(h.Handles.COMBdataSample,'Value')==1
%             % time vector is a column
%             try 
%                 Value=datenum(rawData,h.IOData.formatcell.columnIsAbsTime);
%             catch
%                 % not an absolute date/time format
%                 flag=NaN;
%                 return
%             end
%         else
%             % time vector is a row
%             try 
%                 Value=datenum(rawData,h.IOData.formatcell.rowIsAbsTime);
%             catch
%                 % not an absolute date/time format
%                 flag=NaN;
%                 return
%             end
%         end        
%     end
    % it is a date format
    if Value==floor(Value)
        % only in date format
        % use default matlab display 22
        flag=1;
        return
    else
        % date+time format
        % use default matlab display 22
        flag=0;
        return
    end
end
% FOR OTHER CASES
flag=NaN;
