about summary refs log tree commit diff
path: root/wcal.c
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2022-02-19 22:37:24 +0100
committerLeah Neukirchen <leah@vuxu.org>2022-02-19 22:37:24 +0100
commit15dc6ec45285f8bc9af3702965e83532f1011b0c (patch)
tree03d94f6d7583f4464c765d21af529c4c1cac7c1d /wcal.c
parent6dc570e657d6cac10aa2af9c259df6c2cdb4ae02 (diff)
downloadwcal-15dc6ec45285f8bc9af3702965e83532f1011b0c.tar.gz
wcal-15dc6ec45285f8bc9af3702965e83532f1011b0c.tar.xz
wcal-15dc6ec45285f8bc9af3702965e83532f1011b0c.zip
support ISO week notation in -d HEAD master
Diffstat (limited to 'wcal.c')
-rw-r--r--wcal.c19
1 files changed, 18 insertions, 1 deletions
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, &_, &_, &_);
 		}
 	}
 }