[PATCH] Attempt to fix a crash on DM4 Windows import

Lubomir I. Ivanov neolit123 at gmail.com
Thu May 9 09:29:29 PDT 2013


On 9 May 2013 18:09, Dirk Hohndel <dirk at hohndel.org> wrote:
> On Thu, 2013-05-09 at 09:50 +0300, Miika Turkia wrote:
>> It appears that Windows returns NULL when converting DM4 database's date
>> stamps to local time. (This is due to DM4 using time since year 1, not
>> epoch and Windows doing "sanity checking" on the time.)
>>
>> This patch moves the conversion of time format directly to database
>> query so the localtime should function on Windows. It will also fail
>> gracefully in case of NULL (with error message: failed to parse input).
>>
>> Signed-off-by: Miika Turkia <miika.turkia at gmail.com>
>> ---
>> +     /*
>> +      * I am not sure about the timezones when it comes to Suunto
>> +      * DM4. However, with a sample on GMT+2 and another in GMT+1
>> +      * this code seems to work.
>> +      * Remaining question is, how to handle daylight savings.
>> +      * (Samples I have are contradicting each other...)
>> +      */
>> +     tm->tm_hour += tm->tm_gmtoff / 3600;
>> +     tm->tm_min += tm->tm_gmtoff % 3600;
>
> tm_gmtoff is an extension that I believe does not exist on Windows...
>

http://www.gnu.org/software/libc/manual/html_node/Broken_002ddown-Time.html
"The tm_gmtoff field is derived from BSD and is a GNU library
extension; it is not visible in a strict ISO C environment. "
yes, it's not available...not that Windows is a "strict ISO C environment."

i think this should give a similar result:
time_t raw = time(NULL);
time_t tm_gmtoff = mktime(localtime(&raw)) - mktime(gmtime(&raw));

lubomir
--


More information about the subsurface mailing list