mirror of
https://github.com/esp8266/Arduino.git
synced 2025-05-05 07:24:48 +03:00
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
This commit is contained in:
parent
a67aa569da
commit
3dbac1cab4
@ -433,9 +433,8 @@ bool sntp_set_timezone_in_seconds(sint32 timezone)
|
|||||||
if(timezone >= (-11 * (60 * 60)) || timezone <= (13 * (60 * 60))) {
|
if(timezone >= (-11 * (60 * 60)) || timezone <= (13 * (60 * 60))) {
|
||||||
time_zone = timezone;
|
time_zone = timezone;
|
||||||
return true;
|
return true;
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Sets the timezone in hours. Internally, the timezone is converted to seconds. */
|
/* Sets the timezone in hours. Internally, the timezone is converted to seconds. */
|
||||||
|
10
cores/esp8266/sntp-lwip2.h
Normal file
10
cores/esp8266/sntp-lwip2.h
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#ifndef __sntp_lwip2_h__
|
||||||
|
#define __sntp_lwip2_h__
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
|
||||||
|
bool sntp_set_timezone_in_seconds(sint32 timezone);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -22,6 +22,8 @@
|
|||||||
#include "sntp.h"
|
#include "sntp.h"
|
||||||
#include "coredecls.h"
|
#include "coredecls.h"
|
||||||
|
|
||||||
|
#include "sntp-lwip2.h"
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
||||||
#ifndef _TIMEVAL_DEFINED
|
#ifndef _TIMEVAL_DEFINED
|
||||||
@ -58,7 +60,8 @@ static void setServer(int id, const char* name_or_ip)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void configTime(int timezone, int daylightOffset_sec, const char* server1, const char* server2, const char* server3)
|
|
||||||
|
void configTime(int timezone_sec, int daylightOffset_sec, const char* server1, const char* server2, const char* server3)
|
||||||
{
|
{
|
||||||
sntp_stop();
|
sntp_stop();
|
||||||
|
|
||||||
@ -66,7 +69,7 @@ void configTime(int timezone, int daylightOffset_sec, const char* server1, const
|
|||||||
setServer(1, server2);
|
setServer(1, server2);
|
||||||
setServer(2, server3);
|
setServer(2, server3);
|
||||||
|
|
||||||
sntp_set_timezone(timezone/3600);
|
sntp_set_timezone_in_seconds(timezone_sec);
|
||||||
sntp_set_daylight(daylightOffset_sec);
|
sntp_set_daylight(daylightOffset_sec);
|
||||||
sntp_init();
|
sntp_init();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user