Skip to content

configTime ignores timezone in rc2 #3774

Closed
@dragondaud

Description

@dragondaud

Hardware

Hardware: ESP-12
Core Version: 2.4.0-rc2

Description

After upgrading from 2.4.0-rc1 to 2.4.0-rc2, I noticed the timezone parameter seems to be ignored by configTime, and ctime() returns only GMT. The included sketch demonstrates this problem, and when compiled with rc1 or earlier it shows the correct time output, based on TZ setting. In rc2, the same sketch shows only GMT. If there is an expected change in behavior, I could find no documentation.

Settings in IDE

Module: NodeMCU 1.0
Flash Size: 4MB/1MB
CPU Frequency: 80Mhz
Upload Using: SERIAL

Sketch

#include <ESP8266WiFi.h>
#include <time.h>

#define WIFI_SSID "SSID"
#define WIFI_PASS "PASS"
#define TZ -6

void setup() {
  Serial.begin(115200);
  while (!Serial);
  Serial.println();
  Serial.print("Last reset: ");
  Serial.println(ESP.getResetReason());
  Serial.print("Connecting to ");
  Serial.print(WIFI_SSID);
  Serial.print("...");
  WiFi.begin(WIFI_SSID, WIFI_PASS);
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(500);
  }
  Serial.println();
  Serial.print("Synchronize with NTP...");
  configTime((TZ * 3600), 0, "pool.ntp.org", "time.nist.gov");
  while (!time(nullptr)) {
    delay(1000);
    Serial.print(".");
  }
  Serial.println();
}

void loop() {
  time_t now = time(nullptr);
  String t = ctime(&now);
  t.trim();                       // ctime() output ends with \n, bug?
  long heap = ESP.getFreeHeap();
  Serial.print(heap);
  Serial.print(" free heap @ ");
  Serial.print(t);
  Serial.println();
  delay(5000);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions