Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some POSIX time zones are not handled correctly #7690

Closed
6 tasks done
rjwats opened this issue Nov 2, 2020 · 3 comments · Fixed by #7699 or #7702
Closed
6 tasks done

Some POSIX time zones are not handled correctly #7690

rjwats opened this issue Nov 2, 2020 · 3 comments · Fixed by #7699 or #7702

Comments

@rjwats
Copy link

rjwats commented Nov 2, 2020

Basic Infos

  • This issue complies with the issue POLICY doc.
  • I have read the documentation at readthedocs and the issue is not addressed there.
  • I have tested that the issue is present in current master branch (aka latest git).
  • I have searched the issue tracker for a similar issue.
  • If there is a stack dump, I have decoded it.
  • I have filled out all fields below.

Platform

  • Hardware: [ESP-12]
  • Core Version: [2.7.4]
  • Development Env: [Arduino IDE]
  • Operating System: [Windows]

Settings in IDE

  • Module: [Generic ESP8266 Module]
  • Flash Mode: [dio]
  • Flash Size: [4MB]
  • lwip Variant: [v2 Lower Memory]
  • Reset Method: [nodemcu]
  • Flash Frequency: [40Mhz]
  • CPU Frequency: [80Mhz]
  • Upload Using: [SERIAL]
  • Upload Speed: [115200]

Problem Description

It looks as if some POSIX time zone strings may be being interpreted incorrectly when configured using:

configTime(const char* tz, const char* server1, const char* server2, const char* server3)

or

setTZ(const char* tz)

The following examples have been taken from TZ.h:

The following are some of the values which demonstrate the issue:

#define TZ_America_Sao_Paulo	PSTR("<-03>3") // Offset by +03:00 instead of -03:00
#define TZ_Africa_Casablanca	PSTR("<+01>-1") // Offset by -01:00 instead of +01:00
#define TZ_America_Asuncion	PSTR("<-04>4<-03>,M10.1.0/0,M3.4.0/0") // Offset by +4:00 instead of -03:00

This pattern appears consistent for all time zones which are defined in this format.

By contrast the following (also taken from TZ.h) do not exhibit this issue:

#define TZ_America_Los_Angeles	PSTR("PST8PDT,M3.2.0,M11.1.0") // Offset by -08:00
#define TZ_Europe_Rome	PSTR("CET-1CEST,M3.5.0,M10.5.0/3") // Offset by +01:00
#define TZ_Europe_Kaliningrad	PSTR("EET-2") // Offset by +02:00

All of the examples above were tested today @ ~1604351488 unix timestamp.

MCVE Sketch

#ifndef STASSID
#define STASSID "VM723402-2G"
#define STAPSK  "gmwscxnu"
#endif

#include <TZ.h>

#define MYTZ TZ_America_Sao_Paulo

#include <ESP8266WiFi.h>
#include <coredecls.h>
#include <PolledTimeout.h>

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

extern "C" int clock_gettime(clockid_t unused, struct timespec *tp);

static time_t now;
static esp8266::polledTimeout::periodicMs showTimeNow(5000);

String toISOString(tm* time) {
  char time_string[25];
  strftime(time_string, 25, "%FT%T", time);
  return String(time_string);
}

void showTime() {
  now = time(nullptr);
  Serial.print("gmtime:     ");
  Serial.println(toISOString(gmtime(&now)));
  Serial.print("localtime:  ");
  Serial.println(toISOString(localtime(&now)));
}

void time_is_set_scheduled() {
  showTime();
}

void setup() {
  Serial.begin(115200);
  Serial.println("Starting...");

  settimeofday_cb(time_is_set_scheduled);

  // Set the timezone
  configTime(MYTZ, "pool.ntp.org");

  // start network
  WiFi.persistent(false);
  WiFi.mode(WIFI_STA);
  WiFi.begin(STASSID, STAPSK);
}

void loop() {
  if (showTimeNow) {
    showTime();
  }
}

Debug Messages

One example, when using TZ_America_Sao_Paulo, local time should be offset -03:00, instead it is offset +03:00:

gmtime:     2020-11-02T20:36:51
localtime:  2020-11-02T23:36:51
gmtime:     2020-11-02T20:36:56
localtime:  2020-11-02T23:36:56
gmtime:     2020-11-02T20:37:01
localtime:  2020-11-02T23:37:01
gmtime:     2020-11-02T20:37:06
localtime:  2020-11-02T23:37:06
@d-a-v
Copy link
Collaborator

d-a-v commented Nov 3, 2020

Thanks for the report and MCVE.
This is reproducible.
I don't think it could be on newlib but we are using their API and we make no difference from working TZ and Sao Paulo.
I have so far no idea where it comes from.

@d-a-v
Copy link
Collaborator

d-a-v commented Nov 10, 2020

This is fixed by #7699

@rjwats
Copy link
Author

rjwats commented Nov 10, 2020

Nice, thanks 👍

earlephilhower added a commit to earlephilhower/Arduino that referenced this issue Nov 12, 2020
Undoes the change in esp8266#7699 and fixed esp8266#7690 root cause.

Newlib did not support timezone names of the form "<[+-]?[0-9]+>" and
would parse the offset using the <name>.

Fix newlib tzset parser with
  earlephilhower/newlib-xtensa#14
and undo the UNK changes used as an expedient workaround.
earlephilhower added a commit that referenced this issue Nov 12, 2020
Undoes the change in #7699 and fixed #7690 root cause.

Newlib did not support timezone names of the form "<[+-]?[0-9]+>" and
would parse the offset using the <name>.

Fix newlib tzset parser with
  earlephilhower/newlib-xtensa#14
  earlephilhower/newlib-xtensa#15
and undo the UNK changes used as an expedient workaround.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants