DST

Joel Sherrill joel.sherrill at oarcorp.com
Tue Mar 13 17:40:59 UTC 2007


Eric Norum wrote:
> 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 need some time off.  I am really stressed out trying to get all packed 
up and
ready to leave for Munich on Friday. :(
> 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!
>
Fragile.  :(

I put together the attached init.c so we would have a reference test in 
the future.  Does
it look OK to you?  FWIW tomorrow is celebrated in the local schools as 
Pi day (3/14
in local notation) so I used 3/14  15:9:26 as the time. :)

It should be self-contained.  Give it a spin and I will commit it once I 
hear back.

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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: init.c
Type: text/x-csrc
Size: 1547 bytes
Desc: not available
URL: <http://lists.rtems.org/pipermail/users/attachments/20070313/f53a5b33/attachment-0001.bin>


More information about the users mailing list