]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
cal: support alone month name parameter
authorKarel Zak <kzak@redhat.com>
Fri, 7 Oct 2016 14:02:36 +0000 (16:02 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 7 Oct 2016 14:02:36 +0000 (16:02 +0200)
For example 'cal August' to print August for the current year.

Signed-off-by: Karel Zak <kzak@redhat.com>
misc-utils/cal.1
misc-utils/cal.c

index 2048e95e270c82af121349b4a27eea4bbed9ae6d..39378cfe2af5a4cb0fd54fe1005e9290ae4d1c40 100644 (file)
@@ -44,7 +44,7 @@ cal \- display a calendar
 .br
 .B cal
 [options]
-.RI <timestamp>
+.RI <timestamp|monthname>
 .SH DESCRIPTION
 .B cal
 displays a simple calendar.  If no arguments are specified, the current
@@ -103,10 +103,13 @@ Specifies the \fIyear\fR to be displayed; note the year must be fully specified:
 .B "cal 89"
 will not display a calendar for 1989.
 .TP
-\fBSingle string parameter (e.g. 'cal tomorrow')\fR
-Specifies \fItimestamp\fR. The special placeholders are accepted when parsing timestamp, "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.
+\fBSingle string parameter (e.g. 'cal tomorrow' or 'cal August')\fR
+Specifies \fItimestamp\fR or a \fImonth name\fR according to the current
+locales.
+.sp
+The special placeholders are accepted when parsing timestamp, "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
index aaa2943e6610c53c4e1ac211efee717ace6033c7..5c56e748055c29a698ff5324d37b340b670a6a62 100644 (file)
@@ -410,10 +410,14 @@ int main(int argc, char **argv)
 
        if (argc == 1 && !isdigit_string(*argv)) {
                usec_t x;
+               /* cal <timestamp> */
                if (parse_timestamp(*argv, &x) == 0)
                        now = (time_t) (x / 1000000);
+               /* cal <monthname> */
+               else if ((ctl.req.month = monthname_to_number(&ctl, *argv)) > 0)
+                       time(&now);     /* this year */
                else
-                       errx(EXIT_FAILURE, _("failed to parse timestamp"));
+                       errx(EXIT_FAILURE, _("failed to parse timestamp or unknown month name: %s"), *argv);
                argc = 0;
        } else
                time(&now);
@@ -460,7 +464,8 @@ int main(int argc, char **argv)
        case 0:
                ctl.req.day = local_time->tm_yday + 1;
                ctl.req.year = local_time->tm_year + 1900;
-               ctl.req.month = local_time->tm_mon + 1;
+               if (!ctl.req.month)
+                       ctl.req.month = local_time->tm_mon + 1;
                break;
        default:
                usage(stderr);
@@ -969,6 +974,7 @@ static void __attribute__ ((__noreturn__)) usage(FILE * out)
 {
        fputs(USAGE_HEADER, out);
        fprintf(out, _(" %s [options] [[[day] month] year]\n"), program_invocation_short_name);
+       fprintf(out, _(" %s [options] <timestamp|monthname>\n"), program_invocation_short_name);
 
        fputs(USAGE_SEPARATOR, out);
        fputs(_("Display a calendar, or some part of it.\n"), out);