format.m 2.44 KB
Newer Older
Stéphane Adjemian's avatar
Stéphane Adjemian committed
1
2
3
4
function p = format(date)

%@info:
%! @deftypefn {Function File} {@var{p} =} format (@var{date})
5
%! @anchor{@dynDate/format}
Stéphane Adjemian's avatar
Stéphane Adjemian committed
6
%! @sp 1
7
%! Produces a formatted date from a Dynare date object instantiated by @ref{dynDate}.
Stéphane Adjemian's avatar
Stéphane Adjemian committed
8
9
10
11
12
%! @sp 2
%! @strong{Inputs}
%! @sp 1
%! @table @ @var
%! @item date
13
%! Dynare date object, instantiated by @ref{dynDate}.
Stéphane Adjemian's avatar
Stéphane Adjemian committed
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
%! @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:

Sébastien Villemot's avatar
Sébastien Villemot committed
30
% Copyright (C) 2011-2013 Dynare Team
Stéphane Adjemian's avatar
Stéphane Adjemian committed
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
%
% This file is part of Dynare.
%
% Dynare 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,
% 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/>.

Sébastien Villemot's avatar
Sébastien Villemot committed
47
48
% Original author: stephane DOT adjemian AT univ DASH lemans DOT fr

Stéphane Adjemian's avatar
Stéphane Adjemian committed
49
50

if nargin~=1
51
    error('dynDate::format: I need exactly one input argument!')
Stéphane Adjemian's avatar
Stéphane Adjemian committed
52
53
end

54
55
if ~isa(date,'dynDate')
    error(['dynDate::format: Input argument ' inputname(1) ' has to be a dynDate object!'])
Stéphane Adjemian's avatar
Stéphane Adjemian committed
56
57
58
59
end

switch date.freq
  case 1
60
    p = [num2str(date.time(1)) 'Y'];
Stéphane Adjemian's avatar
Stéphane Adjemian committed
61
62
63
64
65
66
67
  case 4
    p = [num2str(date.time(1)) 'Q' num2str(date.time(2))];
  case 12
    p = [num2str(date.time(1)) 'M' num2str(date.time(2))];
  case 52
    p = [num2str(date.time(1)) 'W' num2str(date.time(2))];
  otherwise
68
    error('dynDate::format: Unkonwn frequency!')
Stéphane Adjemian's avatar
Stéphane Adjemian committed
69
70
71
72
73
74
75
76
77
78
end

%@test:1
%$ % Define some dates
%$ date_1 = 1950;
%$ date_2 = '1950Q2';
%$ date_3 = '1950M10';
%$ date_4 = '1950W50';
%$
%$ % Call the tested routine.
79
80
81
82
%$ d1 = dynDate(date_1); DATE_1 = format(d1);
%$ d2 = dynDate(date_2); DATE_2 = format(d2);
%$ d3 = dynDate(date_3); DATE_3 = format(d3);
%$ d4 = dynDate(date_4); DATE_4 = format(d4);
Stéphane Adjemian's avatar
Stéphane Adjemian committed
83
84
%$
%$ % Check the results.
85
%$ t(1) = dyn_assert([num2str(date_1) 'Y'],DATE_1);
Stéphane Adjemian's avatar
Stéphane Adjemian committed
86
87
88
89
%$ t(2) = dyn_assert(date_2,DATE_2);
%$ t(3) = dyn_assert(date_3,DATE_3);
%$ t(4) = dyn_assert(date_4,DATE_4);
%$ T = all(t);
90
%@eof:1