calendar

BSD calendar reimplementation
git clone https://git.ce9e.org/calendar.git

commit
e29617e655ac1274b1d396884c4f0c3ef3bc29b9
parent
ecb0d75a6e9a390da159ddb37edbcb1ea9762970
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2018-11-19 22:27
c: fix tests

Diffstat

M calendar.c 26 ++++++++++----------------

1 files changed, 10 insertions, 16 deletions


diff --git a/calendar.c b/calendar.c

@@ -56,6 +56,8 @@ struct tpl {
   56    56 	int nth_of_month;
   57    57 	int from_easter;
   58    58 	int from_paskha;
   -1    59 	bool easter;
   -1    60 	bool paskha;
   59    61 };
   60    62 
   61    63 struct line {
@@ -179,16 +181,16 @@ bool is_match(struct tpl tpl, struct tm date) {
  179   181 		}
  180   182 	}
  181   183 
  182    -1 	if (tpl.from_easter) {
   -1   184 	if (tpl.easter) {
  183   185 		struct tm d = add_days(date, -tpl.from_easter);
  184    -1 		if (!date_comp(easter(d.tm_year, false), d)) {
   -1   186 		if (!date_comp(easter(d.tm_year + 1900, false), d)) {
  185   187 			return false;
  186   188 		}
  187   189 	}
  188   190 
  189    -1 	if (tpl.from_paskha) {
   -1   191 	if (tpl.paskha) {
  190   192 		struct tm d = add_days(date, -tpl.from_paskha);
  191    -1 		if (!date_comp(easter(d.tm_year, true), d)) {
   -1   193 		if (!date_comp(easter(d.tm_year + 1900, true), d)) {
  192   194 			return false;
  193   195 		}
  194   196 	}
@@ -206,24 +208,22 @@ struct tpl parse_date(char *s) {
  206   208 		n = atoi(strtok(NULL, ""));
  207   209 	} else if (strchr(s, '-')) {
  208   210 		strtok(s, "-");
  209    -1 		n = atoi(strtok(NULL, ""));
   -1   211 		n = -atoi(strtok(NULL, ""));
  210   212 	}
  211   213 
  212   214 	/* easter */
  213   215 	if (strcmp(s, "Easter") == 0) {
   -1   216 		tpl.easter = true;
  214   217 		tpl.from_easter = n;
  215   218 		return tpl;
  216   219 	}
  217   220 	if (strcmp(s, "Paskha") == 0) {
   -1   221 		tpl.paskha = true;
  218   222 		tpl.from_paskha = n;
  219   223 		return tpl;
  220   224 	}
  221   225 
  222    -1 	bool star = false;
  223    -1 	if (strcmp(s + strlen(s) - strlen("*"), "*") == 0) {
  224    -1 		strcpy(s + strlen(s) - strlen("*"), "");
  225    -1 		star = true;
  226    -1 	}
   -1   226 	bool star = strcmp(s + strlen(s) - strlen("*"), "*") == 0;
  227   227 
  228   228 	struct tm match;
  229   229 
@@ -239,16 +239,10 @@ struct tpl parse_date(char *s) {
  239   239 	} else if (strptime(s, "%m/%a", &match)) {
  240   240 		tpl.month = match.tm_mon + 1;
  241   241 		tpl.weekday = match.tm_wday + 1;
  242    -1 		if (!star) {
  243    -1 			tpl.year = TODAY->tm_year + 1900;
  244    -1 		}
  245   242 		tpl.nth_of_month = n;
  246   243 		return tpl;
  247   244 	} else if (strptime(s, "%a", &match)) {
  248   245 		tpl.weekday = match.tm_wday + 1;
  249    -1 		if (!star) {
  250    -1 			tpl.year = TODAY->tm_year + 1900;
  251    -1 		}
  252   246 		tpl.nth_of_month = n;
  253   247 		return tpl;
  254   248 	}