]> git.netwichtig.de Git - user/henk/code/snooze.git/commitdiff
fix -n with rare events
authorChristian Neukirchen <chneukirchen@gmail.com>
Sat, 2 Jan 2016 20:24:25 +0000 (21:24 +0100)
committerChristian Neukirchen <chneukirchen@gmail.com>
Sat, 2 Jan 2016 20:24:25 +0000 (21:24 +0100)
snooze.c

index 22be6bebc04500b1abda327e769d3e5ba2fea13d..2f4a6ec28a78a94d5ab3daba9a238e0bc1209713 100644 (file)
--- 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);
        }