Package: fp-units-rtl-3.0.0
Version: 3.0.0+dfsg-11
Severity: important
Tags: patch

--- Please enter the report below this line. ---
I'm trying to play with local time / UTC conversion and come to a strange issue

I'm using Linux and seems that the conversion is done in the opposite side

I mean that LocalTimeToUniversal(Now); gives me LT + 2 instead of LT - 2 (I'm in
Paris)
Reproducing this issue is as easy as using the attached file and running this
command:
$ifpc /tmp/utc.pas 
Local TS = 2017-06-02 19:33:614
UTC TS = 2017-06-02 21:33:614
GetLocalTimeOffset = -120
This was submitted to upstream [1] and seems to be fixed with attached patch.
[1]: https://bugs.freepascal.org/view.php?id=31954 id="-x-evo-selection-start-
marker">--- System information. ---Architecture: 
Kernel:       Linux 4.9.0-3-amd64

Debian Release: 9.0
  500 unstable        riot.im 
  500 testing         security.debian.org 
  500 testing         ftp.fr.debian.org 
  500 stable          repo.skype.com 
  500 stable          dl.google.com 
  500 sid             linux.dropbox.com 

--- Package information. ---
Package's Depends field is empty.

Recommends                    (Version) | Installed
=======================================-+-==================
fp-compiler-3.0.0     (= 3.0.0+dfsg-11) | 3.0.0+dfsg-11


Package's Suggests field is empty.
-- 
Cheers,
Abou Al Montacir
program utc;
uses SysUtils, DateUtils;

const
	fmt = 'yyyy-mm-dd HH:M:MSS';

  var
	TS: TDateTime;
begin
	TS := Now;
	WriteLn('Local TS = ', FormatDateTime(fmt, TS));
	TS := LocalTimeToUniversal(TS);
	WriteLn('UTC TS = ', FormatDateTime(fmt, TS));
	WriteLn('GetLocalTimeOffset = ', GetLocalTimeOffset);
end.
From 731f6175a3870c396a7ddaae774ea8a859b4512b Mon Sep 17 00:00:00 2001
From: michael <michael@3ad0048d-3df7-0310-abae-a5850022a9f2>
Date: Fri, 21 Aug 2015 10:36:30 +0000
Subject: [PATCH] * Correct for different meaning of TZOffset

git-svn-id: http://svn.freepascal.org/svn/fpc/trunk@31356 3ad0048d-3df7-0310-abae-a5850022a9f2
---
 packages/rtl-objpas/src/inc/dateutil.inc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/packages/rtl-objpas/src/inc/dateutil.inc b/packages/rtl-objpas/src/inc/dateutil.inc
index c90c83deff..fc7f87a13e 100644
--- a/packages/rtl-objpas/src/inc/dateutil.inc
+++ b/packages/rtl-objpas/src/inc/dateutil.inc
@@ -2532,7 +2532,7 @@ end;
 function UniversalTimeToLocal(UT: TDateTime): TDateTime;
 
 begin
-  Result:=UniversalTimeToLocal(UT,GetLocalTimeOffset);
+  Result:=UniversalTimeToLocal(UT,-GetLocalTimeOffset);
 end;
 
 function UniversalTimeToLocal(UT: TDateTime; TZOffset : Integer): TDateTime;
@@ -2549,7 +2549,7 @@ end;
 Function LocalTimeToUniversal(LT: TDateTime): TDateTime;
 
 begin
-  Result:=LocalTimeToUniversal(LT,GetLocalTimeOffset);
+  Result:=LocalTimeToUniversal(LT,-GetLocalTimeOffset);
 end;
 
 Function LocalTimeToUniversal(LT: TDateTime;TZOffset: Integer): TDateTime;
-- 
2.11.0

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to