Skip to content

Add ESP_PLATFORM support for ISO8601 UTC datetime (RTOS targets) #37

@amarinelli-1994

Description

@amarinelli-1994

Summary

Support for ESP targets using ESP-IDF (FreeRTOS) is currently missing in the platform-specific time handling code.
ESP-IDF provides compatible time.h and sys/time.h APIs.

Problem

Code fails or is excluded when building for ESP-IDF because the platform is not detected.

Example

The following function generates an ISO-8601 UTC timestamp:

#include <sys/time.h>
#include <time.h>

int add_iso8601_utc_datetime(char *buf, size_t size)
{
time_t now;
struct tm timeinfo;

// Format: YYYY-MM-DDThh:mm:ssZ
time(&now);
gmtime_r(&now, &timeinfo);

return strftime(buf, size, "%Y-%m-%dT%H:%M:%SZ", &timeinfo);

}

This code is fully supported by ESP-IDF, which provides:

time()

gmtime_r()

strftime()

Expected behavior

ESP builds should follow the same code path as other POSIX-like systems by detecting:

#if defined(linux) || defined(APPLE) || defined(ESP_PLATFORM)
Why this matters

ESP-IDF is widely used in embedded systems and offers a POSIX-compatible time API on top of FreeRTOS.
Adding ESP_PLATFORM ensures:

consistent behavior across platforms

no need for downstream patches

improved portability for embedded targets

Proposed change

Extend the existing platform detection macros to include ESP:

#if defined(linux) || defined(APPLE) || defined(ESP_PLATFORM)

This keeps the implementation simple and avoids introducing ESP-specific code paths.

Environment

ESP-IDF: 4.x / 5.x

Target: ESP32 / ESP32-S3

RTOS: FreeRTOS (via ESP-IDF)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions