diff --git a/src/@dates/disp.m b/src/@dates/disp.m index 9c012fea451cf02dd3ccd9234cb116fba74d43d8..ce3a9013a5dc15d2ad1270d0576eb0c2f5c798ba 100644 --- a/src/@dates/disp.m +++ b/src/@dates/disp.m @@ -1,15 +1,21 @@ -function disp(dd) +function disp(o) -% Copyright (C) 2013 Dynare Team +% Overloads the disp function for dates object. % -% This file is part of Dynare. +% INPUTS +% - o [dates] % -% Dynare is free software: you can redistribute it and/or modify +% OUTPTS +% None + +% Copyright (C) 2013-2014 Dynare Team +% +% This code is free software: you can redistribute it and/or modify % it under the terms of the GNU General Public License as published by % the Free Software Foundation, either version 3 of the License, or % (at your option) any later version. % -% Dynare is distributed in the hope that it will be useful, +% Dynare dates submodule is distributed in the hope that it will be useful, % but WITHOUT ANY WARRANTY; without even the implied warranty of % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the % GNU General Public License for more details. @@ -17,33 +23,4 @@ function disp(dd) % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <http://www.gnu.org/licenses/>. -if isempty(dd) - fprintf('Empty dates object.\n'); - return -end - -max_displayed = 5; -first_displayed = 2; - -fprintf('<dates: '); - -if dd.ndat<=max_displayed - for i=1:dd.ndat - fprintf(date2string(dd.time(i,:),dd.freq)) - if i<dd.ndat - fprintf(', ') - else - fprintf('>\n') - end - end -else - for i=1:first_displayed - fprintf(date2string(dd.time(i,:),dd.freq)) - fprintf(', ') - end - fprintf(' ..., ') - fprintf(date2string(dd.time(dd.ndat-1,:),dd.freq)) - fprintf(', ') - fprintf(date2string(dd.time(dd.ndat,:),dd.freq)) - fprintf('>\n') -end +fprintf(['\n' dates4display(o, inputname(1), Inf) '\n\n']); \ No newline at end of file diff --git a/src/@dates/display.m b/src/@dates/display.m index 2d230dc8510fd4e828228f4b102b287699e81f52..bc896af58279c3cadb7ceba8ad077a6904ed9fc3 100644 --- a/src/@dates/display.m +++ b/src/@dates/display.m @@ -1,15 +1,21 @@ -function display(dd) +function display(o) -% Copyright (C) 2013 Dynare Team +% Overloads display method for dates object. % -% This file is part of Dynare. +% INPUTS +% - o [dates] % -% Dynare is free software: you can redistribute it and/or modify +% OUTPTS +% None + +% Copyright (C) 2013-2014 Dynare Team +% +% This code is free software: you can redistribute it and/or modify % it under the terms of the GNU General Public License as published by % the Free Software Foundation, either version 3 of the License, or % (at your option) any later version. % -% Dynare is distributed in the hope that it will be useful, +% Dynare dates submodule is distributed in the hope that it will be useful, % but WITHOUT ANY WARRANTY; without even the implied warranty of % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the % GNU General Public License for more details. @@ -17,33 +23,4 @@ function display(dd) % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <http://www.gnu.org/licenses/>. -if isempty(dd) - fprintf('%s is an empty dates object.\n', inputname(1)); - return -end - -max_displayed = 5; -first_displayed = 2; - -fprintf('%s = <dates: ', inputname(1)); - -if dd.ndat<=max_displayed - for i=1:dd.ndat - fprintf(date2string(dd.time(i,:),dd.freq)) - if i<dd.ndat - fprintf(', ') - else - fprintf('>\n') - end - end -else - for i=1:first_displayed - fprintf(date2string(dd.time(i,:),dd.freq)) - fprintf(', ') - end - fprintf(' ..., ') - fprintf(date2string(dd.time(dd.ndat-1,:),dd.freq)) - fprintf(', ') - fprintf(date2string(dd.time(dd.ndat,:),dd.freq)) - fprintf('>\n') -end \ No newline at end of file +fprintf(['\n' dates4display(o, inputname(1), 5) '\n\n']); \ No newline at end of file diff --git a/src/@dates/private/dates4display.m b/src/@dates/private/dates4display.m new file mode 100644 index 0000000000000000000000000000000000000000..7dc6109e2b9d7d9f326ccdfb0be21ebff59dfd6e --- /dev/null +++ b/src/@dates/private/dates4display.m @@ -0,0 +1,48 @@ +function str = dates4display(o, name, max_number_of_elements) + +% Converts a list object to a string. +% +% INPUTS +% - o [list] A dates object to be displayed. +% - name [string] Name of the dates object o. +% - max_number_of_elements [integer] Maximum number of elements displayed. +% +% OUTPUTS +% - str [string] Representation of the dates object as a string. + +% Copyright (C) 2014 Dynare Team +% +% This code is free software: you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation, either version 3 of the License, or +% (at your option) any later version. +% +% Dynare dates submodule is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with Dynare. If not, see <http://www.gnu.org/licenses/>. + +if isempty(o) + str = sprintf('%s is an empty dates object.\n', name); + return +end + +str = sprintf('%s = <dates: ', name); + +if o.length()<=max_number_of_elements + % All the elements are displayed + for i=1:length(o)-1 + str = sprintf('%s%s, ', str, date2string(o.time(i,:),o.freq)); + end +else + % Only display four elements (two first and two last) + for i=1:2 + str = sprintf('%s%s, ', str, date2string(o.time(i,:),o.freq)); + end + str = sprintf('%s%s, ', str, '...'); + str = sprintf('%s%s, ', str, date2string(o.time(o.length()-1,:),o.freq)); +end +str = sprintf('%s%s>', str, date2string(o.time(o.length(),:),o.freq)); \ No newline at end of file