From f25def5a115443186fa325293ed66dce4aaf1ad9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemia=20=28Scylla=29?= <stepan@dynare.org> Date: Wed, 19 Dec 2018 17:18:00 +0100 Subject: [PATCH] Fixed bug. 'A', 'Q', '1900Q', 'Q1', 'M', '1900M', 'M1','W', '1900W' and 'W1' should not be interpreted as dates. --- src/utilities/is/ismonthly.m | 2 +- src/utilities/is/isquarterly.m | 2 +- src/utilities/is/isstringdate.m | 15 +++++++++++++++ src/utilities/is/isweekly.m | 2 +- src/utilities/is/isyearly.m | 2 +- 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/utilities/is/ismonthly.m b/src/utilities/is/ismonthly.m index 60694cf..dcf9c4e 100644 --- a/src/utilities/is/ismonthly.m +++ b/src/utilities/is/ismonthly.m @@ -26,7 +26,7 @@ function b = ismonthly(str) % --*-- Unitary tests --*-- % along with Dynare. If not, see <http://www.gnu.org/licenses/>. if ischar(str) - if isempty(regexp(str,'^-?[0-9]*[Mm]([1-9]|1[0-2])$','once')) + if isempty(regexp(str,'^-?[0-9]+[Mm]([1-9]|1[0-2])$','once')) b = false; else b = true; diff --git a/src/utilities/is/isquarterly.m b/src/utilities/is/isquarterly.m index 1a0a8b3..82811c9 100644 --- a/src/utilities/is/isquarterly.m +++ b/src/utilities/is/isquarterly.m @@ -26,7 +26,7 @@ function b = isquarterly(str) % --*-- Unitary tests --*-- % along with Dynare. If not, see <http://www.gnu.org/licenses/>. if ischar(str) - if isempty(regexp(str,'^-?[0-9]*[Qq][1-4]$','once')) + if isempty(regexp(str,'^-?[0-9]+[Qq][1-4]$','once')) b = false; else b = true; diff --git a/src/utilities/is/isstringdate.m b/src/utilities/is/isstringdate.m index ffbcefc..3221c94 100644 --- a/src/utilities/is/isstringdate.m +++ b/src/utilities/is/isstringdate.m @@ -41,6 +41,13 @@ end %$ date_6 = '1950Y'; %$ date_7 = '-1950a'; %$ date_8 = '1950m '; +%$ date_9 = 'A'; +%$ date_10 = '1938Q'; +%$ date_11 = 'Q4'; +%$ date_12 = '1938M'; +%$ date_13 = 'M11'; +%$ date_14 = '1W'; +%$ date_15 = 'W1'; %$ %$ t(1) = dassert(isstringdate(date_1),true); %$ t(2) = dassert(isstringdate(date_2),true); @@ -50,5 +57,13 @@ end %$ t(6) = dassert(isstringdate(date_6),true); %$ t(7) = dassert(isstringdate(date_7),true); %$ t(8) = dassert(isstringdate(date_8),false); +%$ t(9) = dassert(isstringdate(date_9),false); +%$ t(10) = dassert(isstringdate(date_10),false); +%$ t(11) = dassert(isstringdate(date_11),false); +%$ t(12) = dassert(isstringdate(date_12),false); +%$ t(13) = dassert(isstringdate(date_13),false); +%$ t(14) = dassert(isstringdate(date_14),false); +%$ t(15) = dassert(isstringdate(date_15),false); +%$ %$ T = all(t); %@eof:1 \ No newline at end of file diff --git a/src/utilities/is/isweekly.m b/src/utilities/is/isweekly.m index 8c0a398..a8fdc02 100644 --- a/src/utilities/is/isweekly.m +++ b/src/utilities/is/isweekly.m @@ -26,7 +26,7 @@ function b = isweekly(str) % --*-- Unitary tests --*-- % along with Dynare. If not, see <http://www.gnu.org/licenses/>. if ischar(str) - if isempty(regexp(str,'^-?[0-9]*[Ww]([1-9]|[1-4][0-9]|5[0-2])$','once')) + if isempty(regexp(str,'^-?[0-9]+[Ww]([1-9]|[1-4][0-9]|5[0-2])$','once')) b = false; else b = true; diff --git a/src/utilities/is/isyearly.m b/src/utilities/is/isyearly.m index a1eb711..181b7b4 100644 --- a/src/utilities/is/isyearly.m +++ b/src/utilities/is/isyearly.m @@ -26,7 +26,7 @@ function b = isyearly(str) % --*-- Unitary tests --*-- % along with Dynare. If not, see <http://www.gnu.org/licenses/>. if ischar(str) - if isempty(regexp(str,'^-?[0-9]*[YyAa]$','once')) + if isempty(regexp(str,'^-?[0-9]+[YyAa]$','once')) b = false; else b = true; -- GitLab