Minor TimeLib bug... dayStr() returns "Jan"?

owl-wy7n

Member
Hi Everyone,

I'm a new Teensy 3.6 user. I'm using Arduino 1.8.0 and Teensyduino 1.35.

Here is the source code:

Code:
#include <TimeLib.h>

void setup() 
{
    Serial.begin(250000);
    setTime(RTC_TSR);
}

void loop() 
{
    time_t timeNow = now();
    Serial.printf("\n%s, %02u%s%u %02u:%02u:%02u", 
                  dayShortStr( weekday(timeNow) ),
                  day(timeNow), monthShortStr(month(timeNow)), 
                  year(timeNow), hour(timeNow), minute(timeNow), 
                  second(timeNow) 
                 );
}

The output:
Code:
Jan, 23Jan2017 16:30:57

Shouldn't it be?:
Code:
Mon, 23Jan2017 16:30:57

I tried dayStr( weekday(timeNow) ). It does the same. It also displays 'Jan' instead of 'Monday'.

Am I using this function incorrectly?

Not a big deal. Just reporting what appears to be a bug. I don't actually need the function. I was just doing some testing and noticed.

BTW - I was pleasantly disappointed that the RTC is auto-magically programmed and the time is set. I was preparing to write a driver. Super kudos!
 
Working as designed :(

That is all of the string functions in this library use one character buffer and returns a pointer to that buffer, so last call wins.

That is the call: monthShortStr(month(timeNow))
Will return the same pointer and it overwrote the output of the dayShortStr.

This program returns more what you are expecting...
Code:
#include <TimeLib.h>

void setup() 
{
    Serial.begin(250000);
    setTime(RTC_TSR);
}

void loop() 
{
    time_t timeNow = now();
    Serial.printf("\n%s,", dayShortStr( weekday(timeNow) ));
    Serial.printf(" %02u%s%u %02u:%02u:%02u", 
                  day(timeNow), monthShortStr(month(timeNow)), 
                  year(timeNow), hour(timeNow), minute(timeNow), 
                  second(timeNow) 
                 );
}
 
Back
Top