Fixed: account for milliseconds in XML DateTime longer than 3 digits
This commit is contained in:
parent
1af5bae544
commit
d4cee0403c
@ -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);
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user