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.

CC3220: Time functions gmtime and localtime not working as expected

Part Number: CC3220


Hi,

I am trying to correctly retrieve the month and day of the month of a fixed UTC timestamp.

I am using CGT-ARM 16.9.4LTS in my project which offers the functions gmtime and localtime for example. However, the output is not correct.


To prove this, I run the following c code, both on a linux reference platform and on the CC3220. It basically picks the UTC timestamp of about now, and goes back 30 years in time, and 30 years into the future on the say day, and dumps the current month and day of the month.

void timelibtest() {
    char buf[512];
    long stamp = 1518782314;
    struct tm x;
    int days = -356*30;

    while(days < 356*30)
    {
        stamp = 1518782314 + days*3600*24;
        time_t cstamp = stamp;
        x = *gmtime(&cstamp);
        //x = *localtime(&cstamp);
        sprintf(buf, "UTC %u, MONTH %d, MDAY %d", stamp, x.tm_mon + 1, x.tm_mday );

        CONSOLE_PRINT("%s", buf); /* long converted to string */
        days++;
    }
    return;
}

algo.txt

void timelibtest() {
    char buf[512];
    long stamp = 1518782314;
    struct tm x;
    int days = -356*30;

    while(days < 356*30)
    {
        stamp = 1518782314 + days*3600*24;
        time_t cstamp = stamp;
        x = *gmtime(&cstamp);
        //x = *localtime(&cstamp);
        sprintf(buf, "UTC %u, MONTH %d, MDAY %d", stamp, x.tm_mon + 1, x.tm_mday );

        CONSOLE_PRINT("%s", buf); /* long converted to string */
        days++;
    }
    return;
}

The result in output diffing shows that only in about half of the cases, it gets it right.

For example, the current month (feb 2018) in UTC is wrong, the next month is correct, etc

I've seen in the code that timezones and DST are not supported, but UTC conversion should always work no?

Thanks for your feedback!

Kind regards,

Arnout