* fixed StrToDate to throw proper exceptions in case of an error, fixes bug #3913

git-svn-id: trunk@156 -
This commit is contained in:
florian 2005-05-30 20:37:35 +00:00
parent a39fd9d2ea
commit 4f30642b4a
3 changed files with 31 additions and 3 deletions

1
.gitattributes vendored
View File

@ -6112,6 +6112,7 @@ tests/webtbs/tw3893.pp svneol=native#text/plain
tests/webtbs/tw3898.pp svneol=native#text/plain
tests/webtbs/tw3899.pp svneol=native#text/plain
tests/webtbs/tw3900.pp svneol=native#text/plain
tests/webtbs/tw3913.pp svneol=native#text/plain
tests/webtbs/tw3939.pp svneol=native#text/plain
tests/webtbs/tw3953a.pp svneol=native#text/plain
tests/webtbs/tw3953b.pp svneol=native#text/plain

View File

@ -369,7 +369,7 @@ begin
begin
if (s[i] in ['0'..'9']) then
s1 := s1 + s[i];
if (s[i] in [dateseparator,' ']) or (i = length(s)) then
if (s[i] in [dateseparator,' ']) or ((i = length(s)) and (s[i] in ['0'..'9'])) then
begin
inc(n);
if n>3 then
@ -378,7 +378,9 @@ begin
if c<>0 then
Raise EConvertError.Create('Invalid date format');
s1 := '';
end ;
end
else if not (s[i] in ['0'..'9']) then
Raise EConvertError.Create('Invalid date format');
end ;
// Fill in values.
getLocalTime(LocalTime);
@ -416,7 +418,7 @@ begin
if (TwoDigitYearCenturyWindow > 0) and (Y < ly) then
Inc(Y, 100);
end;
Result := DoEncodeDate(y, m, d);
Result := EncodeDate(y, m, d);
end ;

25
tests/webtbs/tw3913.pp Normal file
View File

@ -0,0 +1,25 @@
{ $mode objfpc}
uses
sysutils;
var
d : tdatetime;
begin
try
d:=strtodate('03'+dateseparator+'03'+dateseparator+'2033');
except
halt(1);
end;
writeln(1);
try
d:=strtodate('2.2/2');
halt(1);
except
end;
writeln(2);
try
d:=strtodate('33'+dateseparator+'33'+dateseparator+'33');
halt(1);
except
end;
writeln('ok');
end.