working timezone config

This commit is contained in:
Siwat Sirichai 2024-05-22 00:06:12 +07:00
parent b30cfde0b0
commit b62ef700ed
3 changed files with 9 additions and 9 deletions

View File

@ -183,14 +183,14 @@ bool ESPMegaPRO::updateTimeFromNTP()
return true;
}
#include <sstream>
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);
}
/**

View File

@ -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);

View File

@ -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");