1
0
mirror of synced 2024-09-07 21:45:03 +00:00

Fixed: account for milliseconds in XML DateTime longer than 3 digits

This commit is contained in:
Mark van Renswoude 2016-05-04 11:48:14 +00:00
parent 1af5bae544
commit d4cee0403c
2 changed files with 19 additions and 3 deletions

View File

@ -14,6 +14,7 @@ type
procedure TestXMLToDate;
procedure TestDateTimeToXML;
procedure TestDateToXML;
procedure TestLongMilliseconds;
end;
@ -94,6 +95,11 @@ begin
end;
procedure TXMLDataBindingUtilsTest.TestLongMilliseconds;
begin
CheckEquals('04-05-2016 13:17:08.013', FormatDateTime('dd-mm-yyyy hh:nn:ss.zzz', XMLToDateTime('2016-05-04T11:17:08.0136668Z', xdtDateTime)));
end;
initialization
RegisterTest(TXMLDataBindingUtilsTest.Suite);

View File

@ -314,6 +314,7 @@ var
msec: Integer;
hasTimezone: Boolean;
xmlOffset: Integer;
endPos: Integer;
begin
Result := 0;
@ -373,11 +374,20 @@ begin
begin
if time[1] = '.' then
begin
{ Parse milliseconds (.zzz) }
if not TryStrToInt(Copy(time, 2, 3), msec) then
{ Parse milliseconds (.zzz+) }
Delete(time, 1, 1);
endPos := 1;
while (endPos <= Length(time)) and (CharInSet(time[endPos], ['0'..'9'])) do
Inc(endPos);
Dec(endPos);
if (endPos = 0) or (not TryStrToInt(Copy(time, 1, Min(endPos, 3)), msec)) then
msec := 0;
Delete(time, 1, 4);
if endPos > 0 then
Delete(time, 1, endPos);
end;
end;