IAR <time.h>, localtime, mktime

I am using DLib for your IAR compiler and would like to convert UTC timestamp to local timestamp.

I am hosted in Germany, so my implementation for the __getzone method is as follows:

char const * __getzone() {
  return ":GMT+1:GMT+2:0100:(1980)032502+0:102503+0";
}

      

I wrote some test codes:

time_t ts = 1509238797L;//29.10.2017-02:59:57 3 seconds before dst
struct tm* pre = localtime(&ts);

time_t after = ts + 5L;//wait 5 seconds -> 29.10.2017-02:00:02
struct tm* post = localtime(&after);

      

The variable "pre" is good, but the variable "post" contains the value: 10/29/2017 - 03:00: 02, but it should be 2017/10/29 - 02: 00: 02.

I've debugged the code in Visual Studio and everything seems to work there. Did I miss something?

+3


source to share


1 answer


I think I found it myself. Right line: GMT + 1: GMT + 2: 0100: 032502 + 0: 102502 + 0

DST starts at 2 pm and ends at 2 pm and I don't think I was thinking at 3 pm. I think the api description is not quite perfect.



Some tests for checking DST transitions:

//Forward
time_t ts = 1490489997L;//26.03.2017-01:59:57 3 seconds before dst
struct tm* pre = localtime(&ts);

time_t after = ts + 5L;//wait 5 seconds -> 26.03.2017-03:00:02
struct tm* post = localtime(&after);

//Backward
time_t ts = 1509238797L;//29.10.2017-02:59:57 3 seconds before dst
struct tm* pre = localtime(&ts);

time_t after = ts + 5L;//wait 5 seconds -> 29.10.2017-02:00:02
struct tm* post = localtime(&after);

      

+1


source







All Articles