diff --git a/src/calendar.c b/src/calendar.c index c02121dd..159150a9 100644 --- a/src/calendar.c +++ b/src/calendar.c @@ -2427,7 +2427,7 @@ WriteJSONInfoChain(TrigInfo *ti) } printf("},"); } -void WriteJSONTrigger(Trigger const *t, int include_tags, int today) +void WriteJSONTrigger(Trigger const *t, int include_tags) { /* wd is an array of days from 0=monday to 6=sunday. We convert to array of strings */ @@ -2556,7 +2556,7 @@ static void WriteSimpleEntryProtocol2(CalEntry *e, int today) PrintJSONKeyPairInt("trep", e->tt.rep); } } - WriteJSONTrigger(&e->trig, 0, today); + WriteJSONTrigger(&e->trig, 0); if (e->nonconst_expr) { PrintJSONKeyPairInt("nonconst_expr", e->nonconst_expr); } diff --git a/src/dorem.c b/src/dorem.c index 3a73b755..6967aef9 100644 --- a/src/dorem.c +++ b/src/dorem.c @@ -341,7 +341,7 @@ int DoRem(ParsePtr p) } } if (PurgeMode) { - if (trig.expired || dse < DSEToday) { + if (trig.expired || (!trig.is_todo && dse < DSEToday)) { if (p->expr_happened) { if (p->nonconst_expr) { if (!Hush) { @@ -1515,6 +1515,11 @@ int ShouldTriggerReminder(Trigger const *t, TimeTrig const *tim, int dse, int *e if (t->complete_through != NO_DATE && t->complete_through >= DSEToday) { return 0; } + if (t->complete_through == NO_DATE || t->complete_through < dse) { + if (dse < DSEToday) { + return 1; + } + } } else { if (dse < DSEToday) return 0; } @@ -1794,6 +1799,17 @@ static int ShouldTriggerBasedOnWarn(Trigger const *t, int dse, int *err) Value v; int lastReturnVal = 0; /* Silence compiler warning */ + if (t->is_todo) { + if (t->complete_through != NO_DATE && t->complete_through >= DSEToday) { + return 0; + } + if (t->complete_through == NO_DATE || t->complete_through < dse) { + if (dse < DSEToday) { + return 1; + } + } + } + /* If no proper function exists, barf... */ if (UserFuncExists(t->warn) != 1) { Eprint("%s: `%s'", GetErr(M_BAD_WARN_FUNC), t->warn); diff --git a/src/dosubst.c b/src/dosubst.c index b92ea2f3..f05abd55 100644 --- a/src/dosubst.c +++ b/src/dosubst.c @@ -426,7 +426,11 @@ int DoSubst(ParsePtr p, DynamicBuffer *dbuf, Trigger *t, TimeTrig const *tt, int break; case 'B': - snprintf(s, sizeof(s), "in %d days' time", diff); + if (diff > 0) { + snprintf(s, sizeof(s), "in %d days' time", diff); + } else { + snprintf(s, sizeof(s), "%d days ago", -diff); + } SHIP_OUT(s); break; diff --git a/src/protos.h b/src/protos.h index e65ed89b..252d8179 100644 --- a/src/protos.h +++ b/src/protos.h @@ -218,7 +218,7 @@ void clear_callstack(void); int print_callstack(FILE *fp); void pop_call(void); void FixSpecialType(Trigger *trig); -void WriteJSONTrigger(Trigger const *t, int include_tags, int today); +void WriteJSONTrigger(Trigger const *t, int include_tags); void WriteJSONTimeTrigger(TimeTrig const *tt); int GetOnceDate(void); #ifdef REM_USE_WCHAR diff --git a/src/queue.c b/src/queue.c index 78bf83ec..d59ea169 100644 --- a/src/queue.c +++ b/src/queue.c @@ -704,7 +704,7 @@ json_queue(QueuedRem const *q) } done = 1; printf("{"); - WriteJSONTrigger(&(q->t), 1, DSEToday); + WriteJSONTrigger(&(q->t), 1); WriteJSONTimeTrigger(&(q->tt)); if (TestMode) { snprintf(idbuf, sizeof(idbuf), "42424242"); diff --git a/src/trigger.c b/src/trigger.c index e61d098a..2bf3bbcb 100644 --- a/src/trigger.c +++ b/src/trigger.c @@ -313,12 +313,21 @@ static int GetNextTriggerDate(Trigger *trig, int start, int *err, int *nextstart int simple, mod, omit; /* First: Have we passed the UNTIL date? */ - if (trig->until != NO_UNTIL && + if (!trig->is_todo && + trig->until != NO_UNTIL && trig->until < start) { trig->expired = 1; return -1; /* expired */ } + /* If it's a TODO and complete_through is past today, we're good */ + if (trig->is_todo && + trig->complete_through != NO_DATE && + trig->complete_through >= start) { + trig->expired = 1; + return -1; + } + /* Next: If it's an "AFTER"-type skip, back up until we're at the start of a block of holidays */ if (trig->skip == AFTER_SKIP) {