add support for repeating entries on the last ???day of the month, as I have such meetings... eg. the last friday, 11am, Boardroom - Departmental catchup -Steve Notes: looks good to me. an additional patch to use tolowerrune (see isalpharune(2)) also looks warrented. - erik Reference: /n/atom/patch/applied/calendar-last Date: Tue Feb 4 17:10:44 CET 2014 Signed-off-by: steve@quintile.net Reviewed-by: quanstro --- /sys/src/cmd/calendar.c Tue Feb 4 17:06:49 2014 +++ /sys/src/cmd/calendar.c Tue Feb 4 17:06:52 2014 @@ -137,6 +137,26 @@ "saturday" }; +static int dmsize[] = /* days per month */ +{ + 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 +}; +static int ldmsize[] = /* leap-year days per month */ +{ + 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 +}; + +int +monthlen(Tm *tm) +{ + int y = tm->year+1900; + + if((y%4) == 0 && ((y%100) != 0 || (y%400) == 0)) + return ldmsize[tm->mday]; + else + return dmsize[tm->mday]; +} + /* * Generate two Date structures. First has month followed by day; * second has day followed by month. Link them into list after @@ -189,6 +209,16 @@ nd->p = regcomp(buf); nd->next = Base; Base = nd; + + if(tm->mday + 7 > monthlen(tm)){ + snprint(buf, sizeof buf, "[\t ]*the[\t ]+last[\t ]+%s", day); + if(debug) + print("%s\n", buf); + nd = emalloc(sizeof(Date)); + nd->p = regcomp(buf); + nd->next = Base; + Base = nd; + } snprint(buf, sizeof buf, "^[\t ]*every[ \t]+%s", day); if(debug)