[fpc-devel] Timezones

Michael Van Canneyt michael at freepascal.org
Sun Nov 15 12:00:55 CET 2015



On Sat, 14 Nov 2015, Zachary Vance wrote:

> I'm reporting a bug the Debian reproducibility team came across (in 2.6.4-1), trying to make Pascal builds reproducible. The end goal is to see UTC timestamped output of ppudump.
>
> My understanding of the current behavior is that the timezone file is chosen something like this:
>
> TIMEZONE_FILE = [CONTENT of /etc/timezone if it exists]:/etc/localtime:/usr/lib/zoneinfo/localtime[:/usr/share/zoneinfo if BSD]:/var/db/timezone/localtime:localtime
> If TIMEZONE_FILE doesn't start with / (is a relative path), prepend (${TZDIR} or /usr/share/zoneinfo)
>
> This means that if /etc/timezone or /etc/localtime exist, there is no way to specify that UTC should be used.
>
> ---
>
> The desired behavior probably be to respect the TZ environment variable, which is currently ignored, so the new list would be:
>
> TIMEZONE_FILE = ${TZ}:[CONTENT of /etc/timezone if it exists]:/etc/localtime:/usr/lib/zoneinfo/localtime[:/usr/share/zoneinfo if BSD]:/var/db/timezone/localtime:localtime
> If TIMEZONE_FILE doesn't start with / (is a relative path), prepend (${TZDIR} or /usr/share/zoneinfo)
>
> Additionally, POSIX says that if TZ is set but invalid or empty, it should default to UTC, not to localtime.

Observing the contents of the TZ variable is of course an option, that should not be a problem.
But the default to localtime will most likely not be changed for 2 reasons
a) compatibility with Delphi.
b) backwards compatibility.
FPC does not pretend to be POSIX.

Looking at
   http://www.gnu.org/software/libc/manual/html_node/TZ-Variable.html

I have the following code to determine the name of the timezone file based on the contents of TZ:

fn:=fpgetenv('TZ');
if (fn<>'') then
   if (fn[1]=':') then  // :filename
     begin
     delete(fn,1,1); // Strip :
     if (fn<>'') then
       begin
       if (fn[1]<>'/') then // not absolute
         Exit('/usr/share/zoneinfo/'+fn)
       Exit(fn);  // absolute
       end;
     end;

Would you say this is correct ?

Michael.



More information about the fpc-devel mailing list