Added new interface to dynDate. The constructor accepts a character ('Y', 'A', 'Q', 'M' or 'W') as the second input to specify the frequency instead of an integer (1, 4, 12, or 52). The following expressions are equivalent:
a = dynDate([1945 3],4); a = dynDate([1945 3],'Q');time-shift
parent
d44732a8ca
commit
56be6eb463
|
@ -144,31 +144,45 @@ switch nargin
|
||||||
date = dynDate();
|
date = dynDate();
|
||||||
if isnumeric(b) && isscalar(b) && ismember(b,[1,4,12,52])
|
if isnumeric(b) && isscalar(b) && ismember(b,[1,4,12,52])
|
||||||
date.freq = b;
|
date.freq = b;
|
||||||
if ~isnumeric(a)
|
elseif ischar(b) && isequal(length(b),1) && ismember(upper(b),{'Y','A','W','M','Q'})
|
||||||
error(['dynDate:: Can''t instantiate the class! The first argument ' inputname(a) ' must be numeric!'])
|
b = upper(b);
|
||||||
end
|
switch b
|
||||||
if ~all(isint(a))
|
case {'Y','A'}
|
||||||
error(['dynDate:: Can''t instantiate the class! The first argument ' inputname(a) ' must be a scalar or a 1*2 vector of integers!'])
|
date.freq = 1;
|
||||||
end
|
case 'W'
|
||||||
if ~isequal(size(a),[1,2])
|
date.freq = 52;
|
||||||
if b>1
|
case 'M'
|
||||||
error(['dynDate:: Can''t instantiate the class! The first argument ' inputname(a) ' must be a 1*2 vector of integers.'])
|
date.freq = 12;
|
||||||
end
|
case 'Q'
|
||||||
else
|
date.freq = 4;
|
||||||
if isequal(b,1) && isequal(a(2),1)
|
otherwise
|
||||||
error(['dynDate:: Can''t instantiate the class! The second element of the first input argument ' inputname(a) ' must be equal to one (because freq==1)!'])
|
error(['dynDate:: Can''t instantiate the class! The second argument ' inputname(b) ' must be an integer equal to 1, 4, 12 or 52, or a character equal to ''Y'', ''A'', ''W'', ''M'' or ''Q''!'])
|
||||||
end
|
|
||||||
end
|
|
||||||
if a(2)<=0 || a(2)>b
|
|
||||||
error(['dynDate:: Can''t instantiate the class! The second element of the first argument ' inputname(a) ' must be a positive integer be <=' int2str(b) '!' ])
|
|
||||||
end
|
|
||||||
if length(a)==1
|
|
||||||
date.time = [a, 1];
|
|
||||||
else
|
|
||||||
date.time = a;
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
error(['dynDate:: Can''t instantiate the class! The second argument ' inputname(b) ' must be equal to 1, 4, 12 or 52.'])
|
error(['dynDate:: Can''t instantiate the class! The second argument ' inputname(b) ' must be an integer equal to 1, 4, 12 or 52, or a character equal to ''Y'', ''A'', ''W'', ''M'' or ''Q''!'])
|
||||||
|
end
|
||||||
|
if ~isnumeric(a)
|
||||||
|
error(['dynDate:: Can''t instantiate the class! The first argument ' inputname(a) ' must be numeric!'])
|
||||||
|
end
|
||||||
|
if ~all(isint(a))
|
||||||
|
error(['dynDate:: Can''t instantiate the class! The first argument ' inputname(a) ' must be a scalar or a 1*2 vector of integers!'])
|
||||||
|
end
|
||||||
|
if ~isequal(size(a),[1,2])
|
||||||
|
if date.freq>1
|
||||||
|
error(['dynDate:: Can''t instantiate the class! The first argument ' inputname(a) ' must be a 1*2 vector of integers.'])
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if isequal(date.freq,1) && isequal(a(2),1)
|
||||||
|
error(['dynDate:: Can''t instantiate the class! The second element of the first input argument ' inputname(a) ' must be equal to one (because freq==1)!'])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if a(2)<=0 || a(2)>date.freq
|
||||||
|
error(['dynDate:: Can''t instantiate the class! The second element of the first argument ' inputname(a) ' must be a positive integer be <=' int2str(b) '!' ])
|
||||||
|
end
|
||||||
|
if length(a)==1
|
||||||
|
date.time = [a, 1];
|
||||||
|
else
|
||||||
|
date.time = a;
|
||||||
end
|
end
|
||||||
otherwise
|
otherwise
|
||||||
error('dynDate:: Can''t instantiate the class, wrong calling sequence!')
|
error('dynDate:: Can''t instantiate the class, wrong calling sequence!')
|
||||||
|
|
Loading…
Reference in New Issue