about summary refs log tree commit diff
path: root/wcal.c
diff options
context:
space:
mode:
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, &_, &_, &_);
 		}
 	}
 }