diff options
author | Karel Zak | 2016-05-31 18:27:20 +0200 |
---|---|---|
committer | Karel Zak | 2016-05-31 18:27:20 +0200 |
commit | cd28d6a405c9cfcaf30fe248a4df84133dbfa17a (patch) | |
tree | 09aee2fba8104cc24a521a0769f70f93bc6f8772 /misc-utils/cal.c | |
parent | cal: allow to specify month by name (diff) | |
download | kernel-qcow2-util-linux-cd28d6a405c9cfcaf30fe248a4df84133dbfa17a.tar.gz kernel-qcow2-util-linux-cd28d6a405c9cfcaf30fe248a4df84133dbfa17a.tar.xz kernel-qcow2-util-linux-cd28d6a405c9cfcaf30fe248a4df84133dbfa17a.zip |
cal: support timestamps
For example
$ cal '2 weeks ago'
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'misc-utils/cal.c')
-rw-r--r-- | misc-utils/cal.c | 12 |
1 files changed, 11 insertions, 1 deletions
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) { |