This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Daylight saving time support with CCS time.h



Hi,

I use the time.h from Code Composer Studio. Using UTC it worked fine for converting a timestamp to struct tm and back.
For a actual project localtime() should include daylight saving for the local timezone.

I've tried with _tz from time.h without success

    _tz.daylight = 1;
    _tz.timezone = 3600;
    _tz.dstname[0] = 'C';
    _tz.dstname[1] = 'E';
    _tz.dstname[2] = 'T';
    _tz.dstname[3] = 0;
    _tz.tzname[0] = 'C';
    _tz.tzname[1] = 'E';
    _tz.tzname[2] = 'T';
    _tz.tzname[3] = 0;

Where can I find Information how to use dstname[] fom CCS time module ? How can I use localtime() with daylight saving time on my MSP430 ? Thanks !

Regards,
Martin

  • All suggestions are welcome. Thanks for help !

  • I dimly remember reading somewhere that localtime (timezones and DST) are not supported. But maybe this memory is about an older mspgcc library version.

    Timezones (and especially DST, which is e.g. in Germany set for each year independently by a separate law) add a significant amount of code to the lib, so it makes sense to not include this for use on a small microcontroller. :)

    If you really need it, you can implement it yourself (take a peek into the free source code of e.g. the runtime lib for linux GCC)

  • Thank you very much for your reply !

    > "... add a significant amount of code to the lib"
    This is the reason why I dont want to reinvent the wheel :-)
    With a precalculated table of UTC timestamps for DST switching it is possible to handle this, but using the already running time.h is my favourite.

    The time.h header has timezone related definitions. Any idea where I can found additional information about the implementation from TI (Code Composer Studio)  ?

    time.h:

    /*************************************************************************/
    /* TIME ZONE STRUCTURE DEFINITION                                        */
    /*************************************************************************/
    typedef struct
    {
        short daylight;
        long  timezone;
        char  tzname[4];
        char  dstname[4];
    } TZ;

    extern _DATA_ACCESS TZ _tz;

  • Martin59499 said:
    The time.h header has timezone related definitions.

    So it is compatible with ported software. It doesn't mean that using these defines has any other effect than not causing a compiler error. :)

    But honestly, I don't whether it should work. If you see that it doesn't work, I provided a possible (and likely) explanation. Not necessarily the right one :)

  • For these facilities to be of use use, you would need some mean of knowing:

    1. What timezone you are in;
    2. When "daylight saving" applies in that timezone.

  • Take a look at this site:

    http://www.worldtimezone.com/

    shows that just knowing which timezone you're in is not trivial!

    And then there's the added complication of "daylight saving":

    http://www.worldtimezone.com/daylight.html

    http://en.wikipedia.org/wiki/Daylight_saving_time

    And here's an example of when it all goes wrong: http://ieeexplore.ieee.org/xpl/articleDetails.jsp?arnumber=4079501

  • Martin59499 said:
    The time.h header has timezone related definitions. Any idea where I can found additional information about the implementation from TI (Code Composer Studio)  ?

    The source code for the TI run time library is in:

    <ccs_installation_root>\ccsv5\tools\compiler\msp430_<compiler_version>\lib\rtssrc.zip

    Browsing the source code, I can't see any code for DST switching or list of time zones.

  • Thank you very much !!!

    The link to the LIB sources are a great tip. You are right, I can't also find any timezone related code. Now I have assurance thats not my using of the lib is the problem.

    Thanks a lot for all the help !!!

**Attention** This is a public forum