diff options
author | Christian Neukirchen <chneukirchen@gmail.com> | 2016-01-02 21:24:25 +0100 |
---|---|---|
committer | Christian Neukirchen <chneukirchen@gmail.com> | 2016-01-02 21:24:25 +0100 |
commit | 4ed5559fd3d8ac4c812e166172f8b939977067b6 (patch) | |
tree | 2163ffb7262be49217a36177857ad7334c6e3a8f | |
parent | 191c1c59b7e38d18a359cde58ecdee4c1c420be7 (diff) | |
download | snooze-4ed5559fd3d8ac4c812e166172f8b939977067b6.tar.gz snooze-4ed5559fd3d8ac4c812e166172f8b939977067b6.tar.xz snooze-4ed5559fd3d8ac4c812e166172f8b939977067b6.zip |
fix -n with rare events
-rw-r--r-- | snooze.c | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/snooze.c b/snooze.c index 22be6be..2f4a6ec 100644 --- a/snooze.c +++ b/snooze.c @@ -319,19 +319,22 @@ int main(int argc, char *argv[]) /* dry-run, just output the next 5 dates. */ int i; for (i = 0; i < 5; i++) { - if (t > 0) { - char weekstr[4]; - struct tm *tm = localtime(&t); - strftime(weekstr, sizeof weekstr, "%a", tm); - printf("%s %s %2ldd%3ldh%3ldm%3lds\n", - isotime(tm), - weekstr, - ((t - now) / (60*60*24)), - ((t - now) / (60*60)) % 24, - ((t - now) / 60) % 60, - (t - now) % 60); - } + char weekstr[4]; + struct tm *tm = localtime(&t); + strftime(weekstr, sizeof weekstr, "%a", tm); + printf("%s %s %2ldd%3ldh%3ldm%3lds\n", + isotime(tm), + weekstr, + ((t - now) / (60*60*24)), + ((t - now) / (60*60)) % 24, + ((t - now) / 60) % 60, + (t - now) % 60); t = find_next(t + 1); + if (t < 0) { + fprintf(stderr, + "no satisfying date found within a year.\n"); + exit(2); + } } exit(0); } |