-
Notifications
You must be signed in to change notification settings - Fork 7.1k
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
net: sntp: Added timezone support on sntp #87434
base: main
Are you sure you want to change the base?
net: sntp: Added timezone support on sntp #87434
Conversation
It was added timezone feature on handling SNTP request to synchronize system clock of the device according to global time requested. Signed-off-by: Pedro Ramos <pedrohq.r@hotmail.com>
Hello @pedrohqr, and thank you very much for your first pull request to the Zephyr project! |
@@ -226,6 +226,16 @@ config NET_CONFIG_SNTP_INIT_SERVER | |||
e.g. server information at | |||
https://support.ntp.org/bin/view/Servers/NTPPoolServers | |||
|
|||
config NET_CONFIG_SNTP_TIMEZONE | |||
bool "Enable timezone control for system clock" | |||
default n |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Options are off by default so we typically do not mention this, so this line can be removed.
@@ -48,7 +59,11 @@ int net_init_clock_via_sntp(void) | |||
goto end; | |||
} | |||
|
|||
tspec.tv_sec = ts.seconds; | |||
#if CONFIG_NET_CONFIG_SNTP_TIMEZONE | |||
tspec.tv_sec = ts.seconds - (UTC_0 - global_tz) * 3600; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is now some misunderstanding how timezones are used. So typically the internal clock is kept in UTC_0 but when presenting the time to the user, the timezone is taken into account and tweaked accordingly. This way for example DST handling is very easy as the internal clock does not need any tweaking when that happens.
So with this in mind, this PR is doing things that are not really needed.
@@ -14,4 +14,6 @@ if(CONFIG_NET_CONFIG_SETTINGS) | |||
) | |||
endif() | |||
|
|||
zephyr_library_sources_ifdef(CONFIG_NET_CONFIG_CLOCK_SNTP_INIT init_clock_sntp.c) | |||
zephyr_include_directories(.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Internal headers shouldn't be exposed globally, whatever needs to be exposed for the app should be placed in a public header.
|
||
void sntp_set_timezone(const enum timezone tz) | ||
{ | ||
global_tz = tz; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that Zephyr uses tabs for indentation.
It was added timezone feature on handling SNTP request to synchronize system clock of the device according to global time requested. In Kconfig was added
NET_CONFIG_CLOCK_SNTP_INIT
bool option were, on enable, include enum timezone in the code, allowing user calling forsntp_set_timezone()
and set the global timezone offset of the current device.