[fpc-devel] FPC V3.0.0 LocalTimeToUniversal() error

LacaK lacak at zoznam.sk
Tue Jun 28 09:43:37 CEST 2016


Dňa 28.6.2016 o 9:18 Michael Van Canneyt napísal(a):
>
>
> On Tue, 28 Jun 2016, Russ Davies wrote:
>
>> Hi,
>>
>> My local time zone is GMT +2, and have noticed that with V3.0.0, that 
>> the LocalTimeToUniversal() function is adding the offset instead of 
>> subtracting it:
>>
>> uses  sysutils, dateutils;
>> var
>>  LocalTime: TDateTime;
>> begin
>>  LocalTime := Now();
>>  writeln('Offset     :', GetLocalTimeOffset());
>>  writeln('Local Time :', TimeToStr(LocalTime));
>>  writeln('UTC        :', TimeToStr(LocalTimeToUniversal(LocalTime)));
>> end.
>>
>> Under 2.6.4 produces:
>>
>> Offset     : -120
>> Local Time : 05:29:13
>> UTC        : 03:29:13
>>
>> With 3.0.0:
>>
>> Offset     :-120
>> Local Time :05:31:16
>> UTC        :07:31:16
>>
>> Comparing dateutil.inc for both versions, in functions 
>> UniversalTimeToLocal() and LocalTimeToUniversal() the signs of the 
>> offsets have been changed
IIRC original implementation was based on Microsoft logic of 
GetTimeZoneInformation, where is stated:

"All translations between UTC time and local time are based on the 
following formula:

UTC = local time + bias

The bias is the difference, in minutes, between UTC time and local time."

-Laco.




More information about the fpc-devel mailing list