From dbee3bcc0dc38ff2a72ffb854850a6f5cda91dc0 Mon Sep 17 00:00:00 2001 From: florian Date: Thu, 22 Apr 2021 20:14:00 +0000 Subject: [PATCH] * fixed MSecsToTimeStamp by Lagunov Aleksey, resolves #38631 git-svn-id: trunk@49247 - --- .gitattributes | 1 + rtl/objpas/sysutils/dati.inc | 12 +++++++----- tests/webtbs/tw38631.pp | 23 +++++++++++++++++++++++ 3 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 tests/webtbs/tw38631.pp diff --git a/.gitattributes b/.gitattributes index 024d18e56e..0639bfd29b 100644 --- a/.gitattributes +++ b/.gitattributes @@ -18820,6 +18820,7 @@ tests/webtbs/tw38549c.pp svneol=native#text/plain tests/webtbs/tw38549d.pp svneol=native#text/plain tests/webtbs/tw38557.pp svneol=native#text/pascal tests/webtbs/tw3863.pp svneol=native#text/plain +tests/webtbs/tw38631.pp svneol=native#text/pascal tests/webtbs/tw38636.pp svneol=native#text/plain tests/webtbs/tw3864.pp svneol=native#text/plain tests/webtbs/tw38642.pp svneol=native#text/pascal diff --git a/rtl/objpas/sysutils/dati.inc b/rtl/objpas/sysutils/dati.inc index 19848e57bf..667d7c1360 100644 --- a/rtl/objpas/sysutils/dati.inc +++ b/rtl/objpas/sysutils/dati.inc @@ -75,18 +75,20 @@ end; { MSecsToTimeStamp } function MSecsToTimeStamp(MSecs: comp): TTimeStamp; +var + D1:Int64; begin - result.Date := Trunc(msecs / msecsperday); - msecs:= msecs-comp(result.date)*msecsperday; - result.Time := Round(MSecs); -end ; + D1:=Trunc(msecs); + result.Date := D1 div msecsperday; + result.Time := D1 - result.date * msecsperday; +end; { TimeStampToMSecs } function TimeStampToMSecs(const TimeStamp: TTimeStamp): comp; begin result := TimeStamp.Time + comp(timestamp.date)*msecsperday; -end ; +end; Function TryEncodeDate(Year,Month,Day : Word; Out Date : TDateTime) : Boolean; diff --git a/tests/webtbs/tw38631.pp b/tests/webtbs/tw38631.pp new file mode 100644 index 0000000000..76448e4516 --- /dev/null +++ b/tests/webtbs/tw38631.pp @@ -0,0 +1,23 @@ +{$mode objfpc} +program msec_test1; +uses sysutils; + +var + D: TDateTime; + T, T1, T2: TTimeStamp; + MS: Comp; +begin + D:=EncodeDate(2021, 03, 16) + EncodeTime(14, 02, 15, 1); + WriteLn('DATE: ', DateTimeToStr(D)); + + T:=DateTimeToTimeStamp(D); + WriteLn(' T.Date=',T.Date,' T.Time=', T.Time); + MS:=TimeStampToMSecs(T); + T1:=MSecsToTimeStamp(MS); + WriteLn('T1.Date=',T1.Date,' T1.Time=', T1.Time); + + WriteLn('DATE1: ', DateTimeToStr(TimeStampToDateTime(T1))); + if TimeStampToDateTime(T1)<>D then + halt(1); + writeln('ok') +end.