better time zone handling

This commit is contained in:
Jörg Deckert 2020-10-25 15:58:40 +01:00
parent dfdac04820
commit 334fecb472
3 changed files with 8 additions and 11 deletions

View File

@ -59,7 +59,7 @@ const uint8_t *digits[10] = { image_data_icon_digit_0, image_data_icon_digit_1,
char *ssid = "Freifunk";
char *pass = "";
char *calendarURL = "https://mail.unitas-network.de/mergedCalendars.json";
int timeZone = 2;
char *timeZone = "CET-1CEST,M3.5.0/02,M10.5.0/03";
//Set to 1 to flip the screen 180 degrees
#define ROTATION 3
@ -98,9 +98,8 @@ void setup() {
display.load1b();
//Update data
// if (timeDigits[0]+timeDigits[1]+timeDigits[2]+timeDigits[3] == 0) {
if ((timeDigits[1] == 5) && (timeDigits[0] == 9)) {
network.begin(); // every midnight set the time from internet
network.begin(); // every hour set the time from internet
network.off();
networking = true;
}

View File

@ -34,15 +34,13 @@ void Network::begin()
// Gets time from ntp server
void Network::getTime(int *timeDigits)
{
// Get seconds since 1.1.1970.
time_t nowSecs = time(nullptr);
// Used to store time
struct tm timeinfo;
gmtime_r(&nowSecs, &timeinfo);
// Setting time string timezone (Better defined modulo, in case timezone makes hours to go below 0)
timeinfo.tm_hour = ((timeinfo.tm_hour + timeZone) % 24 + 24) %24;
setenv("TZ", timeZone, 1);
tzset();
time_t nowSecs = time(nullptr);
localtime_r(&nowSecs, &timeinfo);
// fill in the digits
timeDigits[0] = timeinfo.tm_min % 10; //minutes (units)

View File

@ -4,7 +4,7 @@
#include <WiFiClientSecure.h>
// To get vars from main file
extern int timeZone;
extern char *timeZone;
extern char calName[5][31];
extern char calStart[5][26];
extern char calTitle[5][81];