[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug #58455] Timezone calculation is not portable and uses flag instead

From: Mohammad Akhlaghi
Subject: [bug #58455] Timezone calculation is not portable and uses flag instead of seconds
Date: Wed, 27 May 2020 12:08:18 -0400 (EDT)
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:76.0) Gecko/20100101 Firefox/76.0


                 Summary: Timezone calculation is not portable and uses flag
instead of seconds
                 Project: GNU Astronomy Utilities
            Submitted by: makhlaghi
            Submitted on: Wed 27 May 2020 05:08:16 PM BST
                Category: Libraries
                Severity: 3 - Normal
              Item Group: Crash
                  Status: Confirmed
                 Privacy: Public
             Assigned to: makhlaghi
             Open/Closed: Open
         Discussion Lock: Any



This bug was initially submitted to the address@hidden
mailing list by Alexey Dokuchaev (thanks a lot Alexey! this is a great point).
I am defining it as a bug here to treat it more formally (and assign a number
to it).


The problem is with bug #57995, or more precisely, with
Commit 51ee136
<> which
attempts to correct it. Actually, there are two problems with it. 

1. It does not look right to me that you're subtracting "daylight". As per the
comment in the <time.h> it is a flag if daylight-saving time is ever in use. 
I don't think it's correct to do the math on its value (true/false), e.g.,
subtract from time_t which is seconds). I believe you just need to subtract
the timezone (the UTC offset) as it already should include any required DST
adjustment, but I'm not an expert on those things.

2. Second, the code is not portable.  While X/Open XSI does specify both
global variables, implementations typically discourage the use of external
variables; the tm_zone entry in the tm structure is preferred.  Consider the
following pseudo-code which should work everywhere:

t = mktime(&tp);
 * The function localtime() converts the time value pointed
 * by parameter, and returns pointer to a "struct tm" internal
 * static object which contains the information for the current
 * time zone and other factors such as Daylight Saving Time).
t += localtime(&t)->tm_gmtoff;

Ideally, perhaps you should also check for mktime() return value (if the time
cannot be represented, it returns -1) but I guess you are aware of that and
know what you're going.


Reply to this item at:


  Message sent via Savannah

reply via email to

[Prev in Thread] Current Thread [Next in Thread]