function eventStr = getTimeStr(e,varargin)

%% String representation of event time. If the event parent time series
%% has an absolute time vector, the event time will be converted into the
%% corresponding absolute frame of reference. Result is returned as a 
%% cell array to accomdate arrays of events. Optional second argument is 
%% the requested units (if different from the time units used in the parent
%% time series)

eventStr = cell(size(e));
for k=1:length(e)
    if ~isempty(e(k).Parent) && ishandle(e(k).Parent) && ~isempty(e(k).Parent.TimeInfo.StartDate)
        if ~isempty(e(k).Parent.TimeInfo.Format)
            eventStr{k} = datestr(e(k).Time*tsunitconv('days',e(k).Parent.TimeInfo.Units)+...
                  datenum(e(k).Parent.TimeInfo.StartDate),e(k).Parent.TimeInfo.Format);
        else
            eventStr{k} = datestr(e(k).Time*tsunitconv('days',e(k).Parent.TimeInfo.Units)+...
                  datenum(e(k).Parent.TimeInfo.StartDate));
        end
    else
        if nargin>=2 && ~isempty(varargin{1})
            eventStr{k} = sprintf('%0.3g',e(k).Time*tsunitconv(varargin{1},...
                e(k).Parent.TimeInfo.Units));
        else
            eventStr{k} = sprintf('%0.3g',e(k).Time);
        end
    end
end