summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--misc-utils/cal.117
-rw-r--r--misc-utils/cal.c12
2 files changed, 28 insertions, 1 deletions
diff --git a/misc-utils/cal.1 b/misc-utils/cal.1
index 683e67d19..11e97462c 100644
--- a/misc-utils/cal.1
+++ b/misc-utils/cal.1
@@ -41,6 +41,10 @@ cal \- display a calendar
.B cal
[options]
.RI [[[ day ] " month" ] " year" ]
+.br
+.B cal
+[options]
+.RI <timestamp>
.SH DESCRIPTION
.B cal
displays a simple calendar. If no arguments are specified, the current
@@ -48,6 +52,19 @@ month is displayed.
.sp
The \fImonth\fR may be specified as a number (1-12) or as a month name according
to the current locales.
+.sp
+.B cal
+accepts special placeholders when parsing \fItimestamp\fR, "now" may be used to
+refer to the current time, "today", "yesterday", "tomorrow" refer to
+of the current day, the day before or the next day, respectively.
+.sp
+The relative date specifications are also accepted, in this case "+" is
+evaluated to the current time plus the specified time span. Correspondingly, a
+time span that is prefixed with "-" is evaluated to the current time minus the
+specified time span, for example '+2days'. Instead of prefixing the time span
+with "+" or "-", it may also be suffixed with a space and the word "left" or
+"ago" (for example '1 week ago').
+
.SH OPTIONS
.TP
\fB\-1\fR, \fB\-\-one\fR
diff --git a/misc-utils/cal.c b/misc-utils/cal.c
index c48de69f5..13d8b44be 100644
--- a/misc-utils/cal.c
+++ b/misc-utils/cal.c
@@ -74,6 +74,7 @@
#include "mbsalign.h"
#include "strutils.h"
#include "optutils.h"
+#include "timeutils.h"
static int has_term = 0;
static const char *Senter = "", *Sexit = ""; /* enter and exit standout mode */
@@ -402,7 +403,16 @@ int main(int argc, char **argv)
} else
ctl.week_width = ctl.day_width * DAYS_IN_WEEK;
- time(&now);
+ if (argc == 1 && !isdigit_string(*argv)) {
+ usec_t x;
+ if (parse_timestamp(*argv, &x) == 0)
+ now = (time_t) (x / 1000000);
+ else
+ errx(EXIT_FAILURE, _("failed to parse timestamp"));
+ argc = 0;
+ } else
+ time(&now);
+
local_time = localtime(&now);
switch(argc) {