mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-05-29 19:02:32 +02:00
* Fixed rounding errors in DateTimeToTimeStamp, causing errors in conversions
git-svn-id: trunk@23334 -
This commit is contained in:
parent
9ca374c0c6
commit
2a9e12c709
@ -52,10 +52,15 @@ end;
|
|||||||
{ DateTimeToTimeStamp converts DateTime to a TTimeStamp }
|
{ DateTimeToTimeStamp converts DateTime to a TTimeStamp }
|
||||||
|
|
||||||
function DateTimeToTimeStamp(DateTime: TDateTime): TTimeStamp;
|
function DateTimeToTimeStamp(DateTime: TDateTime): TTimeStamp;
|
||||||
|
|
||||||
|
Var
|
||||||
|
D : Double;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
result.Time := Round(abs(Frac(DateTime)) * MSecsPerDay);
|
D:=DateTime * Single(MSecsPerDay);
|
||||||
result.Date := DateDelta + trunc(DateTime);
|
result.Time := Abs(Round(D)) Mod MSecsPerDay;
|
||||||
end ;
|
result.Date := DateDelta + Round(D) div MSecsPerDay;
|
||||||
|
end;
|
||||||
|
|
||||||
{ TimeStampToDateTime converts TimeStamp to a TDateTime value }
|
{ TimeStampToDateTime converts TimeStamp to a TDateTime value }
|
||||||
|
|
||||||
@ -190,7 +195,7 @@ procedure DecodeTime(Time: TDateTime; out Hour, Minute, Second, MilliSecond: wor
|
|||||||
Var
|
Var
|
||||||
l : cardinal;
|
l : cardinal;
|
||||||
begin
|
begin
|
||||||
l := Round(abs(Frac(time)) * MSecsPerDay);
|
l := DateTimeToTimeStamp(Time).Time;
|
||||||
Hour := l div 3600000;
|
Hour := l div 3600000;
|
||||||
l := l mod 3600000;
|
l := l mod 3600000;
|
||||||
Minute := l div 60000;
|
Minute := l div 60000;
|
||||||
@ -894,12 +899,9 @@ var
|
|||||||
StoreStr(pchar(@S[1]), Length(S));
|
StoreStr(pchar(@S[1]), Length(S));
|
||||||
end ;
|
end ;
|
||||||
|
|
||||||
Const
|
|
||||||
msec2 = 1 / (24*60*60*1000*2); // Half a millisecond, for rounding.
|
|
||||||
|
|
||||||
var
|
var
|
||||||
Year, Month, Day, DayOfWeek, Hour, Minute, Second, MilliSecond: word;
|
Year, Month, Day, DayOfWeek, Hour, Minute, Second, MilliSecond: word;
|
||||||
|
DT : TDateTime;
|
||||||
|
|
||||||
procedure StoreFormat(const FormatStr: string; Nesting: Integer; TimeFlag: Boolean);
|
procedure StoreFormat(const FormatStr: string; Nesting: Integer; TimeFlag: Boolean);
|
||||||
var
|
var
|
||||||
@ -1110,8 +1112,8 @@ begin
|
|||||||
{$ifdef MSWindows}
|
{$ifdef MSWindows}
|
||||||
eastasiainited:=false;
|
eastasiainited:=false;
|
||||||
{$endif MSWindows}
|
{$endif MSWindows}
|
||||||
DecodeDateFully(DateTime+Msec2, Year, Month, Day, DayOfWeek);
|
DecodeDateFully(DateTime, Year, Month, Day, DayOfWeek);
|
||||||
DecodeTime(DateTime+Msec2, Hour, Minute, Second, MilliSecond);
|
DecodeTime(DateTime, Hour, Minute, Second, MilliSecond);
|
||||||
ResultLen := 0;
|
ResultLen := 0;
|
||||||
ResultCurrent := @ResultBuffer[0];
|
ResultCurrent := @ResultBuffer[0];
|
||||||
if FormatStr <> '' then
|
if FormatStr <> '' then
|
||||||
|
Loading…
Reference in New Issue
Block a user