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 --- wcal.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'wcal.c') 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