IIRC, TDateTime is a floating point value: the date is represented in the integral part (as days after 1899-12-30) and the time in the decimal part as a fraction of the day.
That is correct.
If OffsetFromUTC() returns a TDateTime or TTime value, then the "date" part will be 0, i.e. 1899-12-30 no matter what is in the "time" part.
That is a good point. And yes, it does returns a TDateTime with the date portion set to 0 and the time portion set to the offset.
Unless the offset is greater than 24 hours, of course
Which it never should be, since the lowest/highest UTC offsets defined are only ±12 hours from UTC.
So, how can I get the proper "email-time"? If I send the email to myself for example at 14:32 (my local time), my email client shows 15:32. What should I set to get the proper 14:32?
Emails use UTC timestamps, which means Indy is calculating your machine's UTC as ±1 hour from UTC. What is your machines ACTUAL UTC offset?
Somehow Lazarus CodeTools barfs on that line. Solution is to modify that line so it looks like (or close) this:
Index: IdGlobal.pas
===================================================================
--- IdGlobal.pas (revision 5496)
+++ IdGlobal.pas (working copy)
@@ -1905,7 +1905,8 @@
{$IFDEF UNIX}
// For linux the user needs to set this variable to be accurate where used (mail, etc)
- GOffsetFromUTC: TDateTime = 0{$IFDEF HAS_DEPRECATED}{$IFDEF USE_SEMICOLON_BEFORE_DEPRECATED};{$ENDIF} deprecated{$ENDIF};
+(* GOffsetFromUTC: TDateTime = 0{$IFDEF HAS_DEPRECATED}{$IFDEF USE_SEMICOLON_BEFORE_DEPRECATED};{$ENDIF} deprecated{$ENDIF}; *)
+ GOffsetFromUTC: TDateTime = 0;(*{$IFDEF HAS_DEPRECATED}{$IFDEF USE_SEMICOLON_BEFORE_DEPRECATED};{$ENDIF} deprecated{$ENDIF}; *)
{$IFDEF DARWIN}
GMachTimeBaseInfo: TTimebaseInfoData;
I'm not having that discussion again. I've covered that issue MANY times before in this forum, search the archives. The whole reason USE_SEMICOLON_BEFORE_DEPRECATED even exists is because of FPC. But if you look in Indy's IdCompilerDefines.inc file, you will notice that USE_SEMICOLON_BEFORE_DEPRECATED is defined only for FPC 2.4.4 through 2.6.1. From FPC 2.6.2 onwards, it is no longer defined, effectively making the declaration:
GOffsetFromUTC: TDateTime = 0 deprecated;
Which has already been proven to work fine in modern FPC versions. If Lazarus's *editor* has a problem with it, that is for the Lazarus team to fix. That is all I'm saying about that issue.
The UTCOffsetToStr(OffsetFromUTC()) gives +0000, which is incorrect.
I'm using Linux and its time display is good.
Can you please confirm whether both UNIX and either KYLIXCOMPAT or USE_BASEUNIX are defined while compiling IdGlobal.pas when building Indy?
If both are defined, OffsetFromUTC() calculates an offset based on the Posix gettimeofday() function.
If either are not defined, OffsetFromUTC() falls back to Indy's GOffsetFromUTC variable, which is 0 by default and must be set manually. In which case, this is a bug in Indy, as those conditionals SHOULD be defined when compiling for Linux.
Well, I found that Remy already wrote this: https://github.com/IndySockets/Indy/issues/245
Beat me to it, I was just about to point that out. As you can see from
this discussion referenced by that ticket, I was made aware of the issue only a few months ago, but as you can read in that discussion, I have already considered using FPC's offset functions and am hesitant to use them because FPC's own documentation states that they return stale data after DST changes. So I haven't applied any fixes to Indy yet.
But, to be honest, I dunno what should I do based on this info.
GetLocalTimeOffset() gives the proper offset (in minutes). How can I pass this value to the Indy?
If Indy is actually calling gettimeofday() (as it should be), and the function is just not returning timezone info back to Indy, then there is nothing you can do about that without altering Indy's source code. Only when Indy has to fallback to its own GOffsetFromUTC variable can you assign your own timezone offset to Indy.