diff --git a/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaProOS.cpp b/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaProOS.cpp index d1a9c41..44b7f07 100644 --- a/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaProOS.cpp +++ b/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaProOS.cpp @@ -183,14 +183,14 @@ bool ESPMegaPRO::updateTimeFromNTP() return true; } -#include - -void ESPMegaPRO::setUTCOffset(int offset) +/** + * @brief Sets the timezone for the internal RTC. + * + * @note This function takes POSIX timezone strings (e.g. "EST5EDT,M3.2.0,M11.1.0"). +*/ +void ESPMegaPRO::setTimezone(const char* offset) { - std::ostringstream oss; - oss << "UTC" << (offset >= 0 ? "+" : "") << offset; - setenv("TZ", oss.str().c_str(), 1); - tzset(); + setenv("TZ", offset, 1); } /** diff --git a/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaProOS.hpp b/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaProOS.hpp index 2721a58..f78bc86 100644 --- a/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaProOS.hpp +++ b/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaProOS.hpp @@ -52,7 +52,7 @@ class ESPMegaPRO { void enableIotModule(); void enableInternalDisplay(HardwareSerial *serial); void enableWebServer(uint16_t port); - void setUTCOffset(int offset); + void setTimezone(const char* offset); rtctime_t getTime(); void dumpFRAMtoSerial(uint16_t start, uint16_t end); void dumpFRAMtoSerialASCII(uint16_t start, uint16_t end); diff --git a/ESPMegaPRO-OS-SDK/src/main.cpp b/ESPMegaPRO-OS-SDK/src/main.cpp index 03572b6..d73714b 100644 --- a/ESPMegaPRO-OS-SDK/src/main.cpp +++ b/ESPMegaPRO-OS-SDK/src/main.cpp @@ -163,7 +163,7 @@ void setup() { ESP_LOGI("Initializer", "Starting ESPMegaPRO OOP demo"); espmega.begin(); - espmega.setUTCOffset(7); + espmega.setTimezone("UTC-7"); ESP_LOGI("Initializer", "Enabling IOT module"); espmega.enableIotModule(); ESP_LOGI("Initializer", "Enabling Ethernet");