summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2022-09-19 20:58:21 -0400
committerJune McEnroe <june@causal.agency>2022-09-19 20:58:21 -0400
commit4aa4e5d9b13190e94fe97664598f2dc70187a889 (patch)
tree14a28c7115c4527ede342515b0d97ec7549dffec
parentPublish Apologies (diff)
downloadsrc-4aa4e5d9b13190e94fe97664598f2dc70187a889.tar.gz
src-4aa4e5d9b13190e94fe97664598f2dc70187a889.zip
Add when - to print all named dates
Diffstat (limited to '')
-rw-r--r--bin/man1/when.19
-rw-r--r--bin/when.y12
2 files changed, 18 insertions, 3 deletions
diff --git a/bin/man1/when.1 b/bin/man1/when.1
index 64f51cae..3f2735f7 100644
--- a/bin/man1/when.1
+++ b/bin/man1/when.1
@@ -1,4 +1,4 @@
-.Dd August 15, 2022
+.Dd September 19, 2022
 .Dt WHEN 1
 .Os
 .
@@ -9,6 +9,8 @@
 .Sh SYNOPSIS
 .Nm
 .Op Ar expr
+.Nm
+.Cm -
 .
 .Sh DESCRIPTION
 .Nm
@@ -18,6 +20,11 @@ If no
 is given,
 expressions are read
 from standard input.
+If
+.Cm -
+is given,
+the intervals between each named date
+and today are printed.
 .
 .Pp
 The grammar is as follows:
diff --git a/bin/when.y b/bin/when.y
index 69ccc343..c94c5514 100644
--- a/bin/when.y
+++ b/bin/when.y
@@ -319,8 +319,16 @@ int main(int argc, char *argv[]) {
 	}
 
 	if (argc > 1) {
-		input = argv[1];
-		return yyparse();
+		if (strcmp(argv[1], "-")) {
+			input = argv[1];
+			return yyparse();
+		} else {
+			for (size_t i = 0; i < dates.len; ++i) {
+				printf("%s: ", dates.ptr[i].tm_zone);
+				printScalar(dateDiff(today(), dates.ptr[i]));
+			}
+			return EX_OK;
+		}
 	}
 
 	struct tm date = today();