Skip to content
Snippets Groups Projects
Commit 94ee91bd authored by Stéphane Adjemian's avatar Stéphane Adjemian
Browse files

Allow dates objects as first and third arguments (initial and terminal dates).

parent 2d7d1008
No related branches found
No related tags found
No related merge requests found
...@@ -27,27 +27,52 @@ if isempty(to_id) || isempty(do_id) ...@@ -27,27 +27,52 @@ if isempty(to_id) || isempty(do_id)
end end
if do_id<to_id if do_id<to_id
msg = sprinf('Wrong syntax! The TO keyword must preceed the DO keyword.\n'); msg = sprinf('dseries::from: Wrong syntax! The TO keyword must preceed the DO keyword.\n');
error(get_error_message_0(msg)) error(get_error_message_0(msg))
end end
if ~isdate(varargin{1}) if ~isdate(varargin{1})
msg = sprintf('Wrong syntax! The FROM statement must be followed by a dates object.\n'); % The first argument is not a string formatted date. Test if this argument refers to a dates object
% in the caller workspace.
try
d1 = evalin('caller', varargin{1});
if ~isdates(d1)
error(['dseries::from: Variable ' varargin{1} ' is not a dates object!'])
end
catch
error(['dseries::from: Variable ' varargin{1} ' is unknown!'])
end
if ~exist('d1')
msg = sprintf('Wrong syntax! The FROM statement must be followed by a string formatted date.\n');
error(get_error_message_0(msg)) error(get_error_message_0(msg))
end end
else
d1 = dates(varargin{1}); % First date
end
if ~isequal(to_id,2) if ~isequal(to_id,2)
msg = sprintf('Wrong syntax! The first dates object must be immediately followed by the TO keyword.\n'); msg = sprintf('dseries::from: Wrong syntax! The first dates object must be immediately followed by the TO keyword.\n');
error(get_error_message_0(msg)) error(get_error_message_0(msg))
end end
if ~isdate(varargin{3}) if ~isdate(varargin{3})
msg = sprintf('Wrong syntax! The TO keyword must be followed by a second dates object.\n'); % The third argument is not a string formatted date. Test if this argument refers to a dates object
% in the caller workspace.
try
d2 = evalin('caller', varargin{3});
if ~isdates(d2)
error(['dseries::from: Variable ' varargin{3} ' is not a dates object!'])
end
catch
error(['dseries::from: Variable ' varargin{3} ' is unknown!'])
end
if ~exist('d2')
msg = sprintf('dseries::from: Wrong syntax! The TO keyword must be followed by a second dates object.\n');
error(get_error_message_0(msg)) error(get_error_message_0(msg))
end end
else
d1 = dates(varargin{1}); % First date
d2 = dates(varargin{3}); % Last date d2 = dates(varargin{3}); % Last date
end
if d1>d2 if d1>d2
error('The first date must preceed the second one!') error('The first date must preceed the second one!')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment