diff options
author | P. J. McDermott <pj@pehjota.net> | 2021-08-28 21:38:33 (EDT) |
---|---|---|
committer | P. J. McDermott <pj@pehjota.net> | 2021-08-29 12:52:20 (EDT) |
commit | d15edf7f6132be7a3b580898dd67267a833a328d (patch) | |
tree | d8a3da3bab86502e24d215e8b38a5abee760046e /src/main.c | |
parent | 595e0bdc74f976aa399810139b4a7d77eeb71bee (diff) | |
download | atsign-d15edf7f6132be7a3b580898dd67267a833a328d.zip atsign-d15edf7f6132be7a3b580898dd67267a833a328d.tar.gz atsign-d15edf7f6132be7a3b580898dd67267a833a328d.tar.bz2 |
Add loop, adjust datetime_parse() param and decls
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 22 |
1 files changed, 17 insertions, 5 deletions
@@ -20,20 +20,32 @@ #include <stdio.h> #include <stdlib.h> #include <time.h> +#include <unistd.h> #include "datetime.h" int main(int argc, const char *argv[]) { - struct tm tm; + time_t arg; + time_t now; + time_t dif; - if (datetime_parse(argc - 1, argv + 1, &tm) < 0) { + if (datetime_parse(argc - 1, argv + 1, &arg) < 0) { return EXIT_FAILURE; } - printf("%d-%02d-%02dT%02d:%02d:%02d\n", - tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, - tm.tm_hour, tm.tm_min, tm.tm_sec); + setvbuf(stdout, NULL, _IONBF, 0); + time(&now); + while (arg > now) { + dif = arg - now; + printf("\r%02d:%02d:%02d", + (int) dif / 60 / 60, + (int) dif / 60 % 60, + (int) dif % 60); + sleep(1); + time(&now); + } + puts(""); return EXIT_SUCCESS; } |