diff --git a/components/time/time_manager.c b/components/time/time_manager.c index ea218d1..0add748 100644 --- a/components/time/time_manager.c +++ b/components/time/time_manager.c @@ -45,7 +45,7 @@ static int time_command_func(int argc, char **argv) { if (argc == 1) { const Time time = get_time(); - printf("%02u:%02u\n", time.hour, time.minute); + printf("%02u:%02u:%02u\n", time.hour, time.minute, time.second); return 0; } else if (argc == 2) { if (strcmp(argv[1], "store") == 0) { @@ -53,9 +53,11 @@ static int time_command_func(int argc, char **argv) return 0; } else { Time time; - const int result - = sscanf(argv[1], "%02u:%02u", &time.hour, &time.minute); - if (result < 2 || time.hour > 23 || time.minute > 59) { + const int result = sscanf( + argv[1], "%02u:%02u:%02u", &time.hour, &time.minute, + &time.second); + if (result < 2 || time.hour > 23 || time.minute > 59 + || time.second > 59) { printf("Invalid time\n"); return 1; } @@ -128,8 +130,8 @@ void time_manager_init(void) } console_register( - "time", "Get, set or store the time", "time [HH:MM] OR time store", - time_command_func); + "time", "Get, set or store the time", + "time [hh:mm:ss] OR time store", time_command_func); console_register( "date", "Get or set the date, or get the day of the week", "date [yyyy-mm-dd] OR date week-day", date_command_func); @@ -152,7 +154,11 @@ Time get_time(void) struct tm timeinfo; (void)localtime_r(&tv.tv_sec, &timeinfo); - return (Time) { .hour = timeinfo.tm_hour, .minute = timeinfo.tm_min }; + return (Time) { + .hour = timeinfo.tm_hour, + .minute = timeinfo.tm_min, + .second = timeinfo.tm_sec, + }; } void set_time(Time time) @@ -164,6 +170,7 @@ void set_time(Time time) timeinfo.tm_hour = time.hour; timeinfo.tm_min = time.minute; + timeinfo.tm_sec = time.second; tv.tv_sec = mktime(&timeinfo); settimeofday(&tv, NULL); diff --git a/components/time/time_manager.h b/components/time/time_manager.h index bbe5865..aec111b 100644 --- a/components/time/time_manager.h +++ b/components/time/time_manager.h @@ -9,6 +9,7 @@ typedef struct { unsigned hour; unsigned minute; + unsigned second; } Time; typedef struct {