- commit
- ee0416da1c5021e51200f587494691cde7c663f2
- parent
- 348f9ed31c63978e1548a135d0d49cb2c74e8396
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2024-08-17 14:41
do not require year in ranges
Diffstat
| M | calendar.c | 42 | +++++++++++++++++++++++++++--------------- |
1 files changed, 27 insertions, 15 deletions
diff --git a/calendar.c b/calendar.c
@@ -25,7 +25,7 @@ 25 25 * 1999/06/15* June 15 (usefull for birthdays) 26 26 * 1999/05/Sun+2 second Sunday in May 1999 27 27 * 1999/06/15+2 June 15 1999 and every second week since then28 -1 * 1999/06/15:1999/06/20 From June 15 1999 to June 20 1999-1 28 * 1999/06/15:06/20 From June 15 1999 to June 20 1999 29 29 * 30 30 * # removed formats (mostly alternative formats) 31 31 * Jun. 15 06/15 @@ -241,6 +241,28 @@ void invalid_date(char *s) { 241 241 fprintf(stderr, "Error: Invalid date template: %s\n", s); 242 242 } 243 243 -1 244 void parse_end(char *s, struct tpl *tpl) { -1 245 struct tm match; -1 246 -1 247 strtok(s, ":"); -1 248 char *s_end = strtok(NULL, ""); -1 249 if (s_end && strptime(s_end, "%Y/%m/%d", &match)) { -1 250 tpl->end_year = match.tm_year + 1900; -1 251 tpl->end_month = match.tm_mon + 1; -1 252 tpl->end_day = match.tm_mday; -1 253 } else if (strptime(s_end, "%m/%d", &match)) { -1 254 tpl->end_year = tpl->year; -1 255 tpl->end_month = match.tm_mon + 1; -1 256 tpl->end_day = match.tm_mday; -1 257 if (tpl->end_month < tpl->month) { -1 258 tpl->end_year += 1; -1 259 } -1 260 } else { -1 261 invalid_date(s); -1 262 exit(1); -1 263 } -1 264 } -1 265 244 266 struct tpl parse_date(char *s) { 245 267 struct tm *TODAY = today(); 246 268 struct tpl tpl = mktpl(); @@ -306,19 +328,7 @@ struct tpl parse_date(char *s) { 306 328 tpl.month = match.tm_mon + 1; 307 329 tpl.day = match.tm_mday; 308 330 if (strchr(s, ':')) {309 -1 strtok(s, ":");310 -1 char *s_n = strtok(NULL, "");311 -1 if (s_n == NULL) {312 -1 invalid_date(s);313 -1 exit(1);314 -1 } else if (strptime(s_n, "%Y/%m/%d", &match)) {315 -1 tpl.end_month = match.tm_mon + 1;316 -1 tpl.end_day = match.tm_mday;317 -1 tpl.end_year = match.tm_year + 1900;318 -1 } else {319 -1 invalid_date(s);320 -1 exit(1);321 -1 }-1 331 parse_end(s, &tpl); 322 332 } else if (star) { 323 333 tpl.year = 0; 324 334 } @@ -328,7 +338,9 @@ struct tpl parse_date(char *s) { 328 338 tpl.year = TODAY->tm_year + 1900; 329 339 tpl.month = match.tm_mon + 1; 330 340 tpl.day = match.tm_mday;331 -1 if (star) {-1 341 if (strchr(s, ':')) { -1 342 parse_end(s, &tpl); -1 343 } else if (star) { 332 344 tpl.year = 0; 333 345 } else if (match.tm_mon < TODAY->tm_mon) { 334 346 tpl.year += 1;