Russ Davies wroteHi,
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:
i get the same over here...
Comparing dateutil.inc for both versions, in functions UniversalTimeToLocal()
and LocalTimeToUniversal() the signs of the offsets have been changed
yeah, it does look backwards... i'm currently -0400 and the program says
2016 Jun 28 03:06:20 -0400
./timetest.2.6.4
Offset :240
Local Time :03:06:21
UTC :07:06:21
2016 Jun 28 03:06:21 -0400
./timetest.3.0.0
Offset :240
Local Time :03:06:22
UTC :23:06:22
i don't understand why LocalTimeToUniversal() isn't more simple... subtracting a negative is the same as adding the positive and subtracting a positive is, well, subtracting... it looks like they were trying to catch and protect from division by zero when the offset is 0 or there is no offset which results in the offset being 0... the following should work and be easier to follow...
Function LocalTimeToUniversal(LT: TDateTime;TZOffset: Integer): TDateTime;
begin
if (TZOffset 0) then
Result := LT - EncodeTime(TZOffset div 60, TZOffset mod 60, 0, 0)
else
Result := LT;
end;
at least they're not trying to determine which timezone specification is in use... the two that i know of are backwards from each other... using the standard (POSIX??) form, i'm EST5EDT (-0500 and -0400) but using the other form (America/New York or Etc/GMT-5 ???) i'm 0500 and 0400 which means that the formula for the standard form is subtracting whereas the other one is adding when going from local time to GMT time... yeah, it gets really twisted and using the wrong form, while correct for your area, can result in time being off by 12 hours (IIRC)...
NOTE: No off-list assistance is given without prior approval.
*Please keep mailing list traffic on the list* unless
private contact is specifically requested and granted.