From 15dc6ec45285f8bc9af3702965e83532f1011b0c Mon Sep 17 00:00:00 2001 From: Leah Neukirchen Date: Sat, 19 Feb 2022 22:37:24 +0100 Subject: support ISO week notation in -d --- README | 8 ++++++-- wcal.1 | 6 +++++- wcal.c | 19 ++++++++++++++++++- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/README b/README index b19ab33..1bdfeeb 100644 --- a/README +++ b/README @@ -4,7 +4,7 @@ NAME wcal – ISO weekly calendar SYNOPSIS - wcal [-13yci] [-d YYYY[-MM[-DD]]] + wcal [-13yci] [-d YYYY[-MM[-DD]]] [-d YYYY-WWW[-D]] DESCRIPTION The wcal utility prints a week-oriented calendar. Each week is prefixed @@ -29,6 +29,10 @@ DESCRIPTION Show the calendar for a different date than today. Implies -y in case only a year is passed. + -d YYYY-WWW[-D] + Show the calendar for a different date (ISO week notation) than + today. Defaults to Monday if no week day is given. + EXIT STATUS The wcal utility exits 0 on success, and >0 if an error occurs. @@ -53,4 +57,4 @@ CAVEATS This program uses a proleptic Gregorian Calendar and may yield unexpected results before 1752. The year 0000 starts on a Saturday. -Void Linux January 30, 2021 Void Linux +Void Linux Feburary 19, 2022 Void Linux diff --git a/wcal.1 b/wcal.1 index 60142bd..6ad706d 100644 --- a/wcal.1 +++ b/wcal.1 @@ -1,4 +1,4 @@ -.Dd January 30, 2021 +.Dd Feburary 19, 2022 .Dt WCAL 1 .Os .Sh NAME @@ -8,6 +8,7 @@ .Nm .Op Fl 13yci .Op Fl d Ar YYYY Ns Op Ar -MM Ns Op Ar -DD +.Op Fl d Ar YYYY Ns Ar - Ns Cm W Ns Ar WW Ns Op Ar -D .Sh DESCRIPTION The .Nm @@ -35,6 +36,9 @@ Show the calendar for a different date than today. Implies .Fl y in case only a year is passed. +.It Fl d Ar YYYY Ns Ar - Ns Cm W Ns Ar WW Ns Op Ar -D +Show the calendar for a different date (ISO week notation) than today. +Defaults to Monday if no week day is given. .El .Sh EXIT STATUS .Ex -std diff --git a/wcal.c b/wcal.c index 3293f42..b555be8 100644 --- a/wcal.c +++ b/wcal.c @@ -103,8 +103,25 @@ parse_isodate(char *optarg, int *y, int *m, int *d) *m = atoi(optarg+5); if (isdigit(optarg[8]) && isdigit(optarg[9]) && - (!optarg[10] || optarg[10] == '-')) + !optarg[10]) *d = atoi(optarg+8); + } else if (optarg[5] == 'W' && + isdigit(optarg[6]) && isdigit(optarg[7]) && + (!optarg[8] || optarg[8] == '-')) { + int w = atoi(optarg+6); + int wd = 1; + + if (isdigit(optarg[9]) && !optarg[10]) + wd = atoi(optarg+9); + + int _; + int corr; + long jan4 = ymd2jd(*y, 1, 4); + jd2ymdwi(jan4, &_, &_, &_, &corr, &_, &_); + corr += 3; + + jd2ymdwi(jan4 - 4 + 7*w + wd - corr, + y, m, d, &_, &_, &_); } } } -- cgit 1.4.1