1
0
mirror of synced 2024-12-22 09:13:07 +01: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 TestXMLToDate;
procedure TestDateTimeToXML; procedure TestDateTimeToXML;
procedure TestDateToXML; procedure TestDateToXML;
procedure TestLongMilliseconds;
end; end;
@ -94,6 +95,11 @@ begin
end; 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 initialization
RegisterTest(TXMLDataBindingUtilsTest.Suite); RegisterTest(TXMLDataBindingUtilsTest.Suite);

View File

@ -314,6 +314,7 @@ var
msec: Integer; msec: Integer;
hasTimezone: Boolean; hasTimezone: Boolean;
xmlOffset: Integer; xmlOffset: Integer;
endPos: Integer;
begin begin
Result := 0; Result := 0;
@ -373,11 +374,20 @@ begin
begin begin
if time[1] = '.' then if time[1] = '.' then
begin begin
{ Parse milliseconds (.zzz) } { Parse milliseconds (.zzz+) }
if not TryStrToInt(Copy(time, 2, 3), msec) then 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; msec := 0;
Delete(time, 1, 4); if endPos > 0 then
Delete(time, 1, endPos);
end; end;
end; end;