From bd33d63c274c5bd13f188d961ed83e85ef0d0442 Mon Sep 17 00:00:00 2001 From: Steve Bennett Date: Mon, 20 May 2019 10:15:43 +1000 Subject: [PATCH] clock scan: Unspecified fields use the current date/time When scanning a time with unspecified fields, those fields should use the current date/time, not 1 Jan 1900. Signed-off-by: Steve Bennett --- jim-clock.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/jim-clock.c b/jim-clock.c index e1c2d76..e489af8 100644 --- a/jim-clock.c +++ b/jim-clock.c @@ -122,7 +122,7 @@ static int clock_cmd_scan(Jim_Interp *interp, int argc, Jim_Obj *const *argv) { char *pt; struct tm tm; - /*time_t now = time(NULL);*/ + time_t now = time(NULL); /* No default format */ struct clock_options options = { 0, NULL }; @@ -137,10 +137,7 @@ static int clock_cmd_scan(Jim_Interp *interp, int argc, Jim_Obj *const *argv) return -1; } - /* Set unspecified fields to 0, e.g. HH:MM becomes 00:00 */ - memset(&tm, 0, sizeof(tm)); - /* But this is 1-based */ - tm.tm_mday = 1; + localtime_r(&now, &tm); pt = strptime(Jim_String(argv[0]), options.format, &tm); if (pt == 0 || *pt != 0) { -- 2.11.4.GIT