function [tod,date] = timeofday(t)
%TIMEOFDAY Elapsed time since midnight for codistributed datetimes.
%   
%   D = TIMEOFDAY(T)
%   [D,DATE] = TIMEOFDAY(T)
%   
%   See also DATETIME/TIMEOFDAY, CODISTRIBUTED.
%   


%   Copyright 2016-2021 The MathWorks, Inc.

if nargout < 2
    tod = codistributed.pElementwiseOp(@timeofday, t);
else
    if ~isempty(t)
        % Use arrayfun to call timeofday in each element of t and request
        % both outputs.
        [tod,date] = arrayfun(@timeofday, t);
    else
        % Call in-memory timeofday for empty inputs to return the correct
        % empties or error.
        lt = getLocalPart(t);
        [tod,date] = timeofday(lt);
        codistr = getCodistributor(t);
        tod = codistributed.pConstructFromReplicated(tod, codistr);
        date = codistributed.pConstructFromReplicated(date, codistr);
    end
end