Skip to content

Commit 3dbac1c

Browse files
devyted-a-v
authored andcommitted
Update time.cpp (#5835)
* Update time.cpp Migrate configTime() to use sntp_set_timezone_in_seconds() to correctly allow timezone spec in seconds without rounding * Add sntp-lwip2.h for timezone function
1 parent a67aa56 commit 3dbac1c

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

cores/esp8266/sntp-lwip2.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -433,9 +433,8 @@ bool sntp_set_timezone_in_seconds(sint32 timezone)
433433
if(timezone >= (-11 * (60 * 60)) || timezone <= (13 * (60 * 60))) {
434434
time_zone = timezone;
435435
return true;
436-
} else {
437-
return false;
438436
}
437+
return false;
439438
}
440439

441440
/* Sets the timezone in hours. Internally, the timezone is converted to seconds. */

cores/esp8266/sntp-lwip2.h

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#ifndef __sntp_lwip2_h__
2+
#define __sntp_lwip2_h__
3+
4+
extern "C" {
5+
6+
bool sntp_set_timezone_in_seconds(sint32 timezone);
7+
8+
}
9+
10+
#endif

cores/esp8266/time.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#include "sntp.h"
2323
#include "coredecls.h"
2424

25+
#include "sntp-lwip2.h"
26+
2527
extern "C" {
2628

2729
#ifndef _TIMEVAL_DEFINED
@@ -58,15 +60,16 @@ static void setServer(int id, const char* name_or_ip)
5860
}
5961
}
6062

61-
void configTime(int timezone, int daylightOffset_sec, const char* server1, const char* server2, const char* server3)
63+
64+
void configTime(int timezone_sec, int daylightOffset_sec, const char* server1, const char* server2, const char* server3)
6265
{
6366
sntp_stop();
6467

6568
setServer(0, server1);
6669
setServer(1, server2);
6770
setServer(2, server3);
6871

69-
sntp_set_timezone(timezone/3600);
72+
sntp_set_timezone_in_seconds(timezone_sec);
7073
sntp_set_daylight(daylightOffset_sec);
7174
sntp_init();
7275
}

0 commit comments

Comments
 (0)