function runningDuration = computeRunningDuration(startTime,finishTime)
% Helper to compute the running duration based on the startTime and
% finishTime for jobs and tasks.

% Copyright 2021 The MathWorks, Inc.

runningDuration = duration();

if ~isempty(startTime)
    % Check that we are dealing with a datetime object
    validateattributes(startTime, {'datetime'}, {'nonempty'});
    if isempty(finishTime)
        % Use the current time to compute the running duration
        currentTime = datetime('now', 'Timezone', 'local');
        runningDuration = currentTime - startTime;
    else
        % Check that we are dealing with a datetime object
        validateattributes(finishTime, {'datetime'}, {'nonempty'});
        runningDuration = finishTime - startTime;
    end
end

end

