%% Calculate Dates Using time2date
% Show that date2time and time2date are the inverse of each other. First compute the time factors using date2time.

Settle = '1-Sep-2002';
Dates = datenum(['31-Aug-2005'; '28-Feb-2006'; '15-Jun-2006'; 
                 '31-Dec-2006']);
Compounding = 2;
Basis = 0;
EndMonthRule = 1;
TFactors = date2time(Settle, Dates, Compounding, Basis,... 
EndMonthRule)

%
% Now use the calculated TFactors in time2date and compare the calculated dates with the original set.

Dates_calc = time2date(Settle, TFactors, Compounding, Basis,... 
EndMonthRule)
datestr(Dates_calc)

%
% Show time2date support for datetime input for Settle.

Settle = '1-Sep-2002';
Dates = datenum(['31-Aug-2005'; '28-Feb-2006'; '15-Jun-2006'; 
                 '31-Dec-2006']);
Compounding = 2;
Basis = 0;
EndMonthRule = 1;
TFactors = date2time(Settle, Dates, Compounding, Basis,... 
EndMonthRule);
Dates_calc = time2date(datetime(Settle,'Locale','en_US'), TFactors,...
Compounding, Basis, EndMonthRule)

% Copyright 2012 The MathWorks, Inc.