DST

Eric Norum norume at aps.anl.gov
Tue Mar 13 17:10:32 UTC 2007


On Mar 13, 2007, at 9:22 AM, Joel Sherrill wrote:

> Eric Norum wrote:
>> On Mar 13, 2007, at 6:29 AM, Joel Sherrill wrote:
>>
>>> Eric Norum wrote:
>>>> Does the newlib that's part of RTEMS-4.7 handle the TZ  
>>>> environment  variable properly?  I've got:
>>>>
>>>> TZ="CST6CDT,M3.2.0,M11.1.0"
>>>>
>>>> but RTEMS is still reporting CST time.
>>>>
>>>>
>>>> I built newlib from:
>>>> NEWLIB=newlib-1.14.0
>>>> NEWLIBDIFF=newlib-1.14.0-rtems4.7-20061019.diff
>>>>
>>>>
>>> What time function are you calling?
>>>
>>> Internally RTEMS does not know timezone.
>>
>> Right, which is why I was asking about newlib.  Here's a little  
>> test code I stuck into an existing application:
>> {
>> struct tm *tm;
>> time_t now;
>> printf("TZ:\"%s\"\n", getenv("TZ"));
>> time(&now);
>> tm = localtime(&now);
>> printf ("%4.4d-%2.2d-%2.2d %2.2d:%2.2d:%2.2d\n", 1900+tm->tm_year,  
>> tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
>> tm = gmtime(&now);
>> printf ("%4.4d-%2.2d-%2.2d %2.2d:%2.2d:%2.2d\n", 1900+tm->tm_year,  
>> tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
>> }
>>
>>
>> And here's the output:
>> TZ:"CST6CDT,M3.2.0,M11.1.0"
>> 2007-02-13 08:04:01
>> 2007-02-13 14:04:01
>>
>> The TZ variable looks right to me.
>> The GMT values are correct.  But the local time is 6 hours behind  
>> (CST) instead of 5 hours behind (CDT).
>>
> time() directly calls __gettimeofday_r() which is in cpukit/ 
> libcsupport and has a comment
> that newlib does not have timezone support.   time() passes a NULL  
> to __gettimeofday_r()
> so even if we did support timezone info at that level, newlib  
> wouldn't get it.
>
> Neither the newlib docs nor Linux man page mention timezone at all  
> for time().
>
> Should you be calling localtime instead of time?

???
I *am* calling localtime() -- it's right there before the second  
printf().

I think that the comment to which you are referring may, "no longer  
be operative" (gotta love those Watergate era terms).   The newlib  
sources  certainly have support for parsing the TZ environment  
variable. I see now what my problem was the way I had the environment  
variable set.  Here's the correct format:

CST6CDT,M 3.2.0,M 11.1.0

The spaces after the M make all the difference!

-- 
Eric Norum <norume at aps.anl.gov>
Advanced Photon Source
Argonne National Laboratory
(630) 252-4793





More information about the users mailing list