mktime problem

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

mktime problem

1,226 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by nkarakotas on Thu Jul 21 12:16:33 MST 2011
Hi,

Im using newlib in order to use the timezone settings redlib doesnt have. I have experimented with some values but I get some strange values. I wonder if anyone has used the functions?

For example I do the following:

   
    tm.tm_hour = 3;
    tm.tm_min = 0;
    tm.tm_sec = 0;
    tm.tm_wday = 0;
    tm.tm_yday = 0;

 tm.tm_year = (2011) - 1900;
    tm.tm_mday = 30;
    tm.tm_mon = 10 - 1;
    tm.tm_isdst = -1;

    _daylight = 1;
    _timezone = 0;
 //   tz = getenv("TZ");
 //   setenv ("TZ", "GMT2", 1);
 //   tz = getenv("TZ");
 //   tzset();

    time = mktime(&tm);

    _daylight = 1;
    _timezone = 2 * 60 * 60;
   tt = localtime(&time);
This outputs the same value when it should be +2

Any thoughts?
0 Kudos
Reply
5 Replies

1,130 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by riscy00 on Sun Nov 01 21:18:45 MST 2015
Hi the link is broken, can you make new one?
0 Kudos
Reply

1,130 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by nkarakotas on Fri Jul 22 06:41:55 MST 2011
Hi,

I successfully converted the time with the following code:
http://www.google.com/codesearch#rYUC1d6HJqM/test678/zipunzip_src/unzip/timezone.c&q=timezone%20lang...

I changed the getEnv to a char *TZ pointer.

Upon my tests it does what I want.

Regards,
Nick
0 Kudos
Reply

1,130 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by whitecoe on Fri Jul 22 05:14:27 MST 2011
Why don't you explain what you are actually trying to achieve here? I seem to remember that the semihosting interface (original defined by ARM) only provides one call which just returns time since 1970 - with no timezone etc information allowed.

Thus I'm not surprised that newlib doesn't do what you want. You will probably need to implement whatever clock functions you want yourself using functionality provided by your target hardware - either fully or by providing stubs to sit under the top level C library functions.
0 Kudos
Reply

1,130 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by TheFallGuy on Fri Jul 22 03:00:04 MST 2011
AFAIK, getenv is a semihosted function - that is, it gets the environment from the host when running under a debugger. My embedded systems doesn't have any environment variables...
0 Kudos
Reply

1,130 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by nkarakotas on Fri Jul 22 02:09:30 MST 2011
Hi,

I tried to use another implementation of mktime with Redlib but the stdlib.h doesnt have an implementation of setenv which is used. I tried to add setenv support but the compiler complains on the environ:

extern char **environ;          /* the global which is your env. */
-- undefined reference to `environ' --


What is the point having a getenv if you can set it?
0 Kudos
Reply