Skip to content

shell: move date_service to sys_clock api #92115

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions samples/subsys/shell/shell_module/overlay-usb.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,3 @@ CONFIG_SHELL_BACKEND_SERIAL_CHECK_DTR=y
CONFIG_USB_CDC_ACM_LOG_LEVEL_OFF=y
CONFIG_UART_LINE_CTRL=y
CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT=n

# POSIX_TIMERS requires an embedded C library while the native USB driver is incompatible with it.
# So let's disable it. Once USB_NATIVE_POSIX supports embedded C libraries this can be removed.
CONFIG_POSIX_API=n
CONFIG_POSIX_TIMERS=n
# DATE_SHELL requires POSIX_TIMERS
CONFIG_DATE_SHELL=n
2 changes: 0 additions & 2 deletions samples/subsys/shell/shell_module/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ CONFIG_THREAD_MONITOR=y
CONFIG_BOOT_BANNER=n
CONFIG_THREAD_NAME=y
CONFIG_DEVICE_SHELL=y
CONFIG_POSIX_API=y
CONFIG_POSIX_TIMERS=y
CONFIG_DATE_SHELL=y
CONFIG_THREAD_RUNTIME_STATS=y
CONFIG_THREAD_RUNTIME_STATS_USE_TIMING_FUNCTIONS=y
Expand Down
2 changes: 0 additions & 2 deletions samples/subsys/shell/shell_module/prj_getopt.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,5 @@ CONFIG_THREAD_MONITOR=y
CONFIG_BOOT_BANNER=n
CONFIG_THREAD_NAME=y
CONFIG_DEVICE_SHELL=y
CONFIG_POSIX_API=y
CONFIG_POSIX_TIMERS=y
CONFIG_DATE_SHELL=y
CONFIG_THREAD_RUNTIME_STATS=y
2 changes: 0 additions & 2 deletions samples/subsys/shell/shell_module/prj_login.conf
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ CONFIG_THREAD_MONITOR=y
CONFIG_BOOT_BANNER=n
CONFIG_THREAD_NAME=y
CONFIG_DEVICE_SHELL=y
CONFIG_POSIX_API=y
CONFIG_POSIX_TIMERS=y
CONFIG_DATE_SHELL=y
CONFIG_THREAD_RUNTIME_STATS=y

Expand Down
2 changes: 1 addition & 1 deletion samples/subsys/shell/shell_module/sample.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
sample:
name: Shell Sample
common:
filter: not CONFIG_NATIVE_LIBC and not CONFIG_SOC_SERIES_BSIM_NRFXX
filter: not CONFIG_SOC_SERIES_BSIM_NRFXX
tests:
sample.shell.shell_module:
platform_exclude: qemu_rx
Expand Down
1 change: 0 additions & 1 deletion subsys/shell/modules/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ config DEVICE_SHELL

config DATE_SHELL
bool "Date shell"
depends on POSIX_TIMERS
default y if !SHELL_MINIMAL
help
This shell provides access to date and time based on Unix time.
Expand Down
12 changes: 3 additions & 9 deletions subsys/shell/modules/date_service.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@

#include <zephyr/sys/timeutil.h>

#if defined(CONFIG_ARCH_POSIX) && defined(CONFIG_EXTERNAL_LIBC)
#include <time.h>
Copy link
Member

@cfriedt cfriedt Jul 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maass-hamburg - I missed this in my initial review, but for gmtime_r(), I believe that <time.h> should be included, and IIRC, that's the only reason for _POSIX_C_SOURCE to be defined above.

Can you re-include <time.h> and add a comment? E.g. something like

diff --git a/subsys/shell/modules/date_service.c b/subsys/shell/modules/date_service.c
index 95ce21185c8..b77f374f3ed 100644
--- a/subsys/shell/modules/date_service.c
+++ b/subsys/shell/modules/date_service.c
@@ -4,13 +4,16 @@
  * SPDX-License-Identifier: Apache-2.0
  */
 
+/* for gmtime_r() */
 #undef _POSIX_C_SOURCE
 #define _POSIX_C_SOURCE 200809L
+
 #include <stdlib.h>
-#include <zephyr/shell/shell.h>
-#include <zephyr/init.h>
 #include <string.h>
+#include <time.h> /* for gmtime_r() */
 
+#include <zephyr/init.h>
+#include <zephyr/shell/shell.h>
 #include <zephyr/sys/timeutil.h>
 
 #define HELP_NONE      "[none]"

#else
#include <zephyr/posix/time.h>
#endif

#define HELP_NONE "[none]"
#define HELP_DATE_SET "[Y-m-d] <H:M:S>"

Expand Down Expand Up @@ -144,7 +138,7 @@ static int cmd_date_set(const struct shell *sh, size_t argc, char **argv)
struct tm tm;
int ret;

clock_gettime(CLOCK_REALTIME, &tp);
sys_clock_gettime(SYS_CLOCK_REALTIME, &tp);

gmtime_r(&tp.tv_sec, &tm);

Expand Down Expand Up @@ -177,7 +171,7 @@ static int cmd_date_set(const struct shell *sh, size_t argc, char **argv)
}
tp.tv_nsec = 0;

ret = clock_settime(CLOCK_REALTIME, &tp);
ret = sys_clock_settime(SYS_CLOCK_REALTIME, &tp);
if (ret != 0) {
shell_error(sh, "Could not set date %d", ret);
return -EINVAL;
Expand All @@ -193,7 +187,7 @@ static int cmd_date_get(const struct shell *sh, size_t argc, char **argv)
struct timespec tp;
struct tm tm;

clock_gettime(CLOCK_REALTIME, &tp);
sys_clock_gettime(SYS_CLOCK_REALTIME, &tp);

gmtime_r(&tp.tv_sec, &tm);

Expand Down
Loading