Issue with dates past the year 2038

I’m developing a program where we would store settings for dates in the future, as well as have an operating life of 25 years. However when using the standard time functions from the le_clk api I’m running into the issue that dates past 2038 seem to give errors.

Is there a solution for this or am I going to have to roll my own time code?


  char timeString[128];
  char* date;
  le_clk_Time_t currentTime = {0};
  date = "2049-12-06 08:23:00";
  le_result_t res = le_clk_ConvertToTime("%Y-%m-%d %H:%M:%S", date, &currentTime);
  le_clk_ConvertToLocalTimeString(currentTime, "%Y-%m-%d %H:%M:%S", timeString, sizeof(timeString), &readSize);
  LE_INFO("%s => %s, %ld, %d", date, timeString, currentTime.sec, res);

This results in:

2049-12-06 08:23:00 => 1969-12-31 23:59:59, -1, -6

hi @shommersom,
this issue known as Y2k38 bug could effectively impact the Legato application framework;
there is a study on going internally to solve that;
Best regards,


The issue with Year 2038 (Y2K38) bug is for any 32-bit platforms running Linux OS, not only Legato platforms.

It is mainly due to the signed 32-bit format used to store the seconds in the time_t typedef (and derivative).

A lot of pieces of software are impacted including kernel and glibc.

There is no official solution from Linux community for this problem.

If possible try not to rely on anything using time_t.

Legato offers some RTC APIs to get/set time past year 2038 (le_rtc_xxx).

If you want to manipulate time/date after 2038 then you can still use functions based on tm struct like strptime or strftime.
Then you can also reuse code from other C library that is safe against Y2K38 like musl libc.

As an example, see this code doing the same stuff as your sample code:

int res;
struct tm tm1, tm2;
char timeString[128];
char date[] = "2049-12-06 08:23:00\x00";
int64_t epoch_seconds;
strptime(date, "%Y-%m-%d %H:%M:%S", &tm1);
epoch_seconds = __tm_to_secs(&tm1);
res = __secs_to_tm(epoch_seconds, &tm2);
strftime(timeString, sizeof(timeString), "%Y-%m-%d %H:%M:%S", &tm2);
LE_INFO("%s => %s, %lld, %d", date, timeString, epoch_seconds, res);

The result is:

2049-12-06 08:23:00 => 2049-12-06 08:23:00, 2522391780, 0

The functions __tm_to_secs and __secs_to_tm are coming from musl libc:

PFA my Legato project:
y2k38.tar.bz2 (10 KB)