Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XMLTimeToDateTime ignores milliseconds

why does XMLTimeToDateTime ignore milliseconds?

  Test := XMLTimeToDateTime('2011-11-11T12:41:36.696+01:00', TRUE);
  T2 := FormatDateTime('yyyy''-''mm''-''dd''T''hh'':''nn'':''ss''.''zzz', Test);

after that T2 = '2011-11-11T11:41:36.000'

I am using Delphi 2007.

like image 896
TmTron Avatar asked Nov 11 '11 12:11

TmTron


1 Answers

The code in XSBuiltIns indeed parses the millisecond part, but this part is never used in encoding functions.

function TXSBaseTime.GetAsTime: TDateTime;
begin
  Result := EncodeTime(Hour, Minute, Second, 0);
end;

and

function TXSBaseCustomDateTime.GetAsDateTime: TDateTime;
var
  BiasDT: TDateTime;
  BiasTime, BiasLocal: Integer;
  BiasHour, BiasMins: Word;
begin
  { NOTE: In XML Years can exceed 9999 - that's not the case for TDateTime.
          So here, there would be a problem with the conversion }
  Result := EncodeDateTime(Year, Month, Day, Hour, Minute, Second, 0);

and

function TXSBaseCustomDateTime.GetAsUTCDateTime: TDateTime;
var
  AdjustDT: TDateTime;
begin
  Result := EncodeDateTime(Year, Month, Day, Hour, Minute, Second, 0);

As the last one is called from XMLTimeToDateTime, it is quite understandable that the millisecond part is always 0.

All parsing and data storage is done in internal (implementation part) classes which cannot be access directly except through (broken) wrappers. IOW, you should write your own date/time parser.


In addition to all the ugliness found in XSBuiltIns, XMLTimeToDateTime actually parses date twice. First the TXSDateTime.XSToNative is called which parses the date/time, throws result away and stores only the original string, and then TXSCustomDateTime.GetAsUTCDateTime parses this string again. Euch!

like image 109
gabr Avatar answered Oct 21 '22 13:10

gabr