function [matdate, date_string, id] = syslog2datenum( elements )

% Convert cell array of timestamped syslog messages to MATLAB date number
% Last modified Jan 22, 2016
% Ben Raanan, MBARI

% extract string containing time stamp
%--------------------------------------------------------------------------
exprs = '(?<year>\d+)-(?<month>\d+)-(?<day>\d+)+T+(?<hh>\d+):(?<mm>\d+):(?<ss>\d+).(?<fff>\d+)';
date_string = regexp(elements,exprs,'match');


% remove elements w/ missing timestamp and convert type to char
%--------------------------------------------------------------------------
id = ~cellfun('isempty', date_string);
date_string = cellfun(@(c) c{1}, date_string(id),'UniformOutput',false);


% remove T from time stamp. format will be: 'yyyy-mm-dd HH:MM:SS'
%--------------------------------------------------------------------------
date_string = regexprep(date_string,'[T]',' ');


% finally, convert to matdate
%--------------------------------------------------------------------------
matdate = datenum(date_string);

end
