


@info:
! @deftypefn {Function File} {@var{p} =} format (@var{date})
! @anchor{@dynDate/format}
! @sp 1
! Produces a formatted date from a Dynare date object instantiated by @ref{dynDate}.
! @sp 2
! @strong{Inputs}
! @sp 1
! @table @ @var
! @item date
! Dynare date object, instantiated by @ref{dynDate}.
! @end table
! @sp 1
! @strong{Outputs}
! @sp 1
! @table @ @var
! @item p
! A string containing the formatted date (for instance, '2000', '2000Q3', '2000M9' or '2000W43').
! @end table
! @sp 2
! @strong{This function is called by:}
! @sp 2
! @strong{This function calls:}
!
! @end deftypefn
@eod:

0001 function p = format(date) 0002 0003 %@info: 0004 %! @deftypefn {Function File} {@var{p} =} format (@var{date}) 0005 %! @anchor{@dynDate/format} 0006 %! @sp 1 0007 %! Produces a formatted date from a Dynare date object instantiated by @ref{dynDate}. 0008 %! @sp 2 0009 %! @strong{Inputs} 0010 %! @sp 1 0011 %! @table @ @var 0012 %! @item date 0013 %! Dynare date object, instantiated by @ref{dynDate}. 0014 %! @end table 0015 %! @sp 1 0016 %! @strong{Outputs} 0017 %! @sp 1 0018 %! @table @ @var 0019 %! @item p 0020 %! A string containing the formatted date (for instance, '2000', '2000Q3', '2000M9' or '2000W43'). 0021 %! @end table 0022 %! @sp 2 0023 %! @strong{This function is called by:} 0024 %! @sp 2 0025 %! @strong{This function calls:} 0026 %! 0027 %! @end deftypefn 0028 %@eod: 0029 0030 % Copyright (C) 2011 Dynare Team 0031 % stephane DOT adjemian AT univ DASH lemans DOT fr 0032 % 0033 % This file is part of Dynare. 0034 % 0035 % Dynare is free software: you can redistribute it and/or modify 0036 % it under the terms of the GNU General Public License as published by 0037 % the Free Software Foundation, either version 3 of the License, or 0038 % (at your option) any later version. 0039 % 0040 % Dynare is distributed in the hope that it will be useful, 0041 % but WITHOUT ANY WARRANTY; without even the implied warranty of 0042 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0043 % GNU General Public License for more details. 0044 % 0045 % You should have received a copy of the GNU General Public License 0046 % along with Dynare. If not, see <http://www.gnu.org/licenses/>. 0047 0048 0049 if nargin~=1 0050 error('dynDate::format: I need exactly one input argument!') 0051 end 0052 0053 if ~isa(date,'dynDate') 0054 error(['dynDate::format: Input argument ' inputname(1) ' has to be a dynDate object!']) 0055 end 0056 0057 switch date.freq 0058 case 1 0059 p = num2str(date.time(1)); 0060 case 4 0061 p = [num2str(date.time(1)) 'Q' num2str(date.time(2))]; 0062 case 12 0063 p = [num2str(date.time(1)) 'M' num2str(date.time(2))]; 0064 case 52 0065 p = [num2str(date.time(1)) 'W' num2str(date.time(2))]; 0066 otherwise 0067 error('dynDate::format: Unkonwn frequency!') 0068 end 0069 0070 %@test:1 0071 %$ addpath ../matlab 0072 %$ 0073 %$ % Define some dates 0074 %$ date_1 = 1950; 0075 %$ date_2 = '1950Q2'; 0076 %$ date_3 = '1950M10'; 0077 %$ date_4 = '1950W50'; 0078 %$ 0079 %$ % Call the tested routine. 0080 %$ d1 = dynDate(date_1); DATE_1 = format(d1); 0081 %$ d2 = dynDate(date_2); DATE_2 = format(d2); 0082 %$ d3 = dynDate(date_3); DATE_3 = format(d3); 0083 %$ d4 = dynDate(date_4); DATE_4 = format(d4); 0084 %$ 0085 %$ % Check the results. 0086 %$ t(1) = dyn_assert(num2str(date_1),DATE_1); 0087 %$ t(2) = dyn_assert(date_2,DATE_2); 0088 %$ t(3) = dyn_assert(date_3,DATE_3); 0089 %$ t(4) = dyn_assert(date_4,DATE_4); 0090 %$ T = all(t); 0091 %@eof:1