%

% Copyright 2017 The MathWorks, Inc.
function addTimeColumnIfNeeded(this, parsedVar)
    import xls.internal.WriteTable;
    nextTimeValues = WriteTable.getParsedVarData(parsedVar, @(x) x.getTimeValues);
    if ~needsTimeColumn(nextTimeValues, parsedVar)
        return;
    end

    if ~isequal(this.CurrentTimeValues, nextTimeValues)
        this.CurrentTimeValues = nextTimeValues;
        timeColWhichFits = this.enforceRectangularData('D', this.CurrentTimeValues, NaN);
        this.D{:, this.CurrentCol} = timeColWhichFits;
        this.addTimeColumn;
    end
end

function bool = needsTimeColumn(nextTimeValues, parsedVar)
    bool = isempty(nextTimeValues) || ...
        isa(parsedVar, 'xls.internal.import.FcnCallInputParser');
    bool = ~bool;
end
