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.

TMS320F280049: Wrong Timezone for Macros TIME and DATE

Part Number: TMS320F280049
Other Parts Discussed in Thread: C2000WARE, CCSTUDIO

Hello,

I am using CCS10.1.1 and C2000Ware 3.3.0.0 and found the following problem:

If I use the macros TIME and DATE in source files to add the production date to my firmware, the time (and propably date also)

is not the time of my local timezone but 1h back, e.g. real time should be 09:41, TIME delivers 08:41. How can I fix this?

IDEs / compilers for not TI micros deliver corrrect values.

Thanks

Steffen

  • I presume you use the standard predefined macros __TIME__ and __DATE__.  Please perform an experiment.  Start with this C code ...

    /* file.c */
    char time_as_string[] = __TIME__;
    char date_as_string[] = __DATE__;

    Build it with the option that creates a preprocessor listing file ...

    cl2000 --gen_preprocessor_listing file.c

    The preprocessor listing file is named file.rl.  It will look similar to ...

    L 1 "file.c"
    N/* file.c */
    Nchar time_as_string[] = __TIME__;
    Xchar time_as_string[] = "09:28:22";
    Nchar date_as_string[] = __DATE__;
    Xchar date_as_string[] = "Mar 25 2021";

    Every line in this listing file begins with a capital letter to indicate the contents of that line.  Specific to this instance, N means a normal line of source copied from the source file.  When the next line begins with X, it is the same as the previous line, but any preprocessor macros are expanded. 

    When you do this experiment, do you see correct values for __TIME__ and __DATE__?

    For further details on preprocessor listing files, please search the C28x compiler manual for the sub-chapter titled Generating a Raw Listing File.

    Thanks and regards,

    -George

  • Thanks George spending your  time.

    Yes, sorry, I mean standard C __TIME__ / __DATE__ Macros.

    I tried your experiment with wrong result (should be 15:52:43)

    L 15 "../src/main.cpp" 2
    N
    Nchar time_as_string[] = __TIME__;
    Xchar time_as_string[] = "14:52:43";
    Nchar date_as_string[] = __DATE__;
    Xchar date_as_string[] = "Mar 25 2021";
    N

    So it seems that preprocessor already set the wrong value. The compiler manual does not really give new information about my problem.

    Does __TIME__ expands on your PC system correctly?

    Thanks.

  • Does __TIME__ expands on your PC system correctly?

    Yes.

    Please start a command line shell on your host system.  Run the appropriate commands to see the current time and date.  For instance, in a Command Prompt shell on a Windows 10 system, it looks similar to ...

    C:\working_directory>date /t
    Thu 03/25/2021
    
    C:working_directory>time /t
    10:10 AM

    What do you see?

    Thanks and regards,

    -George

  • The correct values ... As I mentioned all other compilers I run (gnu, keil, ...) return correct values ...

    Microsoft Windows [Version 10.0.18363.1377]
    (c) 2019 Microsoft Corporation. Alle Rechte vorbehalten.

    C:\Users\cn3gos00>date /t
    25.03.2021

    C:\Users\cn3gos00>time /t
    16:17

    C:\Users\cn3gos00>

  • In the very same command line shell where date and time work correctly, please run the first experiment where you create a preprocessing listing file for file.c.  What do you see then?

    Thanks and regards,

    -George

  • shell with correct time running eclipse command line build, build wrong again ...

  • I'm not sure what you mean by ...

    running eclipse command line build

    Please show a screen shot, or describe how you do it, or something like that.

    Thanks and regards,

    -George

  • I can build my application by CCS eclipse IDE or by batch script and CCS command line interface in command shell:

    eclipsec -noSplash -data %TMP_WORKSPACE_DIR% -application com.ti.ccstudio.apps.projectBuild -ccs.autoImport -ccs.projects %APP_PROJ_NAME% -ccs.buildType build_flash

  • I understand that when building with the eclipsec command, the time is wrong.  Does the same thing happen when you directly build with the compiler shell cl2000?  

    Thanks and regards,

    -George

  • George thanks again spending your time ...

    I tried native with make on cmd  but still no success: same one hour shift

  • Thank you for answering all my questions.  But I remain concerned that eclipsec or make may be a cause of the problem.  To eliminate any such possibility, please run the following experiment.  In the Windows command prompt application, please run these commands exactly as shown.

    C:\working_directory>type file.c
    /* file.c */
    char time_as_string[] = __TIME__;
    char date_as_string[] = __DATE__;
    
    C:\working_directory>time /t
    10:33 AM
    
    C:\working_directory>cl2000 --gen_preprocessor_listing file.c
    
    C:\working_directory>type file.rl
    L 1 "file.c"
    N/* file.c */
    Nchar time_as_string[] = __TIME__;
    Xchar time_as_string[] = "10:33:28";
    Nchar date_as_string[] = __DATE__;
    Xchar date_as_string[] = "Mar 26 2021";

    What do you see?  Does the time /t command match the time for the __TIME__ macro?

    Thanks and regards,

    -George

  • Does the time /t command match the time for the __TIME__ macro?

    Looking at the ti-cgt-c2000_20.2.2.LTS in Windows 10 Pro 20H2, cl2000 is sensitive to the TZ environment variable but time /t isn't. For the following tests time /t and the compilation were run from the same command prompt window

    TZ environment variable time /t result __TIME__ macro result
    <not set> Correct Correct
    UTC-1 Correct One hour ahead
    UTC+1 Correct One hour behind

    The Windows "Time zone" is set to "UTC+00:00 London"

    I tried native with make on cmd  but still no success: same one hour shift

    Does set from the cmd prompt show any TZ variable set?

  • Good morning George, no success. Because of the beginning summer time I see still the time shift of 2 hours:

    C:\ti\ccs1011\ccs\tools\compiler\ti-cgt-c2000_20.2.1.LTS\bin>type file.c
    char time_as_string[] = __TIME__;
    char date_as_string[] = __DATE__;

    C:\ti\ccs1011\ccs\tools\compiler\ti-cgt-c2000_20.2.1.LTS\bin>time /t
    08:19

    C:\ti\ccs1011\ccs\tools\compiler\ti-cgt-c2000_20.2.1.LTS\bin>cl2000 --gen_preprocessor_listing file.c

    C:\ti\ccs1011\ccs\tools\compiler\ti-cgt-c2000_20.2.1.LTS\bin>type file.rl
    L 1 "file.c"
    Nchar time_as_string[] = __TIME__;
    Xchar time_as_string[] = "06:19:50";
    Nchar date_as_string[] = __DATE__;
    Xchar date_as_string[] = "Mar 29 2021";

    C:\ti\ccs1011\ccs\tools\compiler\ti-cgt-c2000_20.2.1.LTS\bin>

  • Hello Chester,

    yes, cmd shows time zone:

    C:\ti\ccs1011\ccs\tools\compiler\ti-cgt-c2000_20.2.1.LTS\bin>systeminfo | findstr /L "Zeitzone:"
    Zeitzone: (UTC+01:00) Amsterdam, Berlin, Bern, Rom, Stockholm, Wien

    C:\ti\ccs1011\ccs\tools\compiler\ti-cgt-c2000_20.2.1.LTS\bin>

    So this and your tests shown, that compiler does not correct uses time zone setting or? But this confuses me because I am sure that Georges environment uses time zone (UTC-5?) too (as propably any other windows system) ...????

  • So this and your tests shown, that compiler does not correct uses time zone setting or?

    What I was trying to say that if there is a TZ environment variable set, that the compiler can use the TZ environment variable to obtain the time zone, rather than the time zone set in the operating system.

    What does set report from your command prompt?

    Not sure if George can find out which library function the TI compiler calls to get the date/time used to populate __DATE__ and __TIME__ macros.

  • which library function the TI compiler calls to get the date/time used to populate __DATE__ and __TIME__ macros

    ANSI C standard functions are used.  time is called to get the number of seconds since the epoch, and ctime is used to format it as a string.

    I'm not sure of the "one true way" the time zone should be configured on Windows.  I have always taken the defaults on this detail, and I've never had a problem.

    Thanks and regards,

    -George

  • cmd shows the wrong timezone:

    D:\cc\CIOS\fw\scripts>set TZ
    TZ=GMT0

    Setting TZ to GMT+1 or WET/WEST will change the __TIME__ value but does not takes care about the daylight saving time like time /t or the windows system time. So using time zone seems to me not the correct way because it does not automatically takes care about DST.

    For compiling the image via batch file using eclipsesc I could set the TZ to the correct value but this does not solve the problem if I compile the image in Eclipse IDE directly.

    This is my the first project running on C2000 but I have a lot experiance with Infineon, STM, Atmel, Microchip, ... All these IDEs (Eclipse, Keil, Tasking, ...) are currently installed on my system and gave correctly times with __TIME__. So they seem to use not timezone values but real system time.

    But on the other side I cannot believe that I am the first detecting this. So still I am searching for specific problem on my ccs1011 installation. I am using ti-cgt-c2000_20.2.1.LTS (not ti-cgt-arm_20.2.1.LTS). Could this be a difference to your systems?

  • Now I made a little console application with Visual Studio. They also use the TZ value for time() and __TIME__ generation. For the real OS time they have _strtime_s() function. So ccs works according MS implementation. After searching in internet it seems that the time base of __TIME__ ist not really standarized in ANSI/ISO. 

    But implementation of __TIME__ according TZ does not make any sense to me because the only reason for usage of __TIME__ is a simple way to add build times to an image and this should be the system time and not something "random" (normal time GMT, DST, ...) else. Other compilers solve this better. May be a compiler option to support both could be the solution.

    So finally: Is there any other simple way to add the real build time to an image? The only I imagine is an own prebuild script manipulating dedicated images bytes with real time values.

  • Now the riddle is solved: I was wondering, why in windows time/date settings the correct timezone and day light setting was enabled (GMT+1 and DST), but the cmd shows TZ=GMT0. So I delete TZ in system settings  and reboot my computer  (necessary) and everything works fine. TI and MS VS __TIME__ delivers correct values now. My system administrator  told me that TZ variable is not set by default in our company network. So we guess that something adds in the last days this to my system. No idea which installation / update this made.

    George and Chester: Thank you very much for your assistance and the trigger idea with the "set TZ" !