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

net: sntp: Added timezone support on sntp #87434

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

pedrohqr
Copy link

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 for sntp_set_timezone() and set the global timezone offset of the current device.

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>
Copy link

Hello @pedrohqr, and thank you very much for your first pull request to the Zephyr project!
Our Continuous Integration pipeline will execute a series of checks on your Pull Request commit messages and code, and you are expected to address any failures by updating the PR. Please take a look at our commit message guidelines to find out how to format your commit messages, and at our contribution workflow to understand how to update your Pull Request. If you haven't already, please make sure to review the project's Contributor Expectations and update (by amending and force-pushing the commits) your pull request if necessary.
If you are stuck or need help please join us on Discord and ask your question there. Additionally, you can escalate the review when applicable. 😊

@@ -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
Copy link
Member

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;
Copy link
Member

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(.)
Copy link
Contributor

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;
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants