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

Bug fix.

Returned year was wrong for yearly frequency.
parent 666138fd
Branches
No related tags found
No related merge requests found
function y = year(d)
function y = year(d) % --*-- Unitary tests --*--
% Returns the year.
......@@ -23,4 +23,85 @@ if d.freq==365
return
end
y = floor((d.time-1)/d.freq);
\ No newline at end of file
if d.freq>1
y = floor((d.time-1)/d.freq);
else
y = d.time;
end
return
%@test:1
try
y = year(dates('2020-01-01'));
t(1) = true;
catch
t(1) = false;
end
if t(1)
t(2) = y==2020;
end
T = all(t);
%@eof:1
%@test:2
try
y = year(dates('1938-11-22'));
t(1) = true;
catch
t(1) = false;
end
if t(1)
t(2) = y==1938;
end
T = all(t);
%@eof:2
%@test:3
try
y = year(dates('2020S2'));
t(1) = true;
catch
t(1) = false;
end
if t(1)
t(2) = y==2020;
end
T = all(t);
%@eof:3
%@test:4
try
y = year(dates('2020Q1'));
t(1) = true;
catch
t(1) = false;
end
if t(1)
t(2) = y==2020;
end
T = all(t);
%@eof:4
%@test:5
try
y = year(dates('2019M3'));
t(1) = true;
catch
t(1) = false;
end
if t(1)
t(2) = y==2019;
end
T = all(t);
%@eof:5
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment