Why is DateTimeToMilliseconds in DateUtils.pas marked as internal?

Why is DateTimeToMilliseconds in DateUtils.pas marked as internal? Can i use it?

{ Internal, converts a date-time to milliseconds } function DateTimeToMilliseconds(const ADateTime: TDateTime): Int64; var LTimeStamp: TTimeStamp; begin LTimeStamp := DateTimeToTimeStamp(ADateTime); Result := LTimeStamp.Date; Result := (Result * MSecsPerDay) + LTimeStamp.Time; end; 

[Delphi XE]


I found this on About.com:

Experience has shown that creating two TDateTime values ​​using a function and EncodeDateTime that are only a millisecond apart from each other, the function returns MillisecondsBetween, rather than returning as expected, proving that it is inaccurate.

So, if I don't care a few milisec, I have to use it.

+4
source share
2 answers

TDateTime is a double floating point. To minimize rounding errors when working with TDateTime values, most calculations in DateUtils convert TDateTime to milliseconds.

Later, when the calculations are ready, the Int64 value again returns to the TDateTime .

The internal labeling is to emphasize that this function is an implementation detail, and not used outside the library. That is, when working with TDateTime values, use public functions / procedures.

This is a small test of the MilliSecondsBetween function:

 program TestMSecBetween; {$APPTYPE CONSOLE} uses System.SysUtils,System.DateUtils; var d1,d2 : TDateTime; i,iSec,iMin,iHour,iMSec; isb : Int64; begin d1 := EncodeDateTime(2013,6,14,0,0,0,0); for i := 0 to 1000*60*60*24-1 do begin iHour := (i div (1000*60*60)) mod 24; iMin := (i div (1000*60)) mod 60; iSec := (i div 1000) mod 60; iMSec := i mod 1000; d2 := EncodeDateTime(2013,6,14,iHour,iMin,iSec,iMSec); isb := MilliSecondsBetween(d2,d1); if (isb <> i) then WriteLn(i:10,iHour:3,iMin:3,iSec:3,iMSec:4,isb:3); end; ReadLn; end. 

You can expand the test for more than one day to find out if there are any anomalies.

+7
source

There is no reason why you could not use it, it is not outdated and not used internally.

It is simply marked as "internal" because the function header is not in the interface section. If you copy the title there, it should work.

What we always do if we “fix” a third-party device like this, copy it to a directory in our own search path (named PatchLibs) before changing it. Thus, you cannot “damage” the source file, and you do not need to worry about how to restore the original units.

+1
source

Source: https://habr.com/ru/post/1486252/


All Articles