diff options
author | florian <florian@3ad0048d-3df7-0310-abae-a5850022a9f2> | 2021-04-22 20:14:00 +0000 |
---|---|---|
committer | florian <florian@3ad0048d-3df7-0310-abae-a5850022a9f2> | 2021-04-22 20:14:00 +0000 |
commit | 16cbe36ee0b8e05bd4b88f35ad237cb2c6ba54aa (patch) | |
tree | b640ee41c42fc0f36e98072857fcbe510d0517ce | |
parent | 622af098008dc21b62c0577ba6435e872052555d (diff) | |
download | fpc-16cbe36ee0b8e05bd4b88f35ad237cb2c6ba54aa.tar.gz |
* fixed MSecsToTimeStamp by Lagunov Aleksey, resolves #38631
git-svn-id: https://svn.freepascal.org/svn/fpc/trunk@49247 3ad0048d-3df7-0310-abae-a5850022a9f2
-rw-r--r-- | rtl/objpas/sysutils/dati.inc | 12 | ||||
-rw-r--r-- | tests/webtbs/tw38631.pp | 23 |
2 files changed, 30 insertions, 5 deletions
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. |