From 6e53fd6924b17bc4e4f959264d2a03387bc3452d Mon Sep 17 00:00:00 2001 From: Dianne Skoll Date: Sat, 9 Dec 2023 10:41:03 -0500 Subject: [PATCH] Refactor code: Replace SystemTime(x)/60 with MinutesPastMidnight(x) --- src/dorem.c | 9 +-------- src/dosubst.c | 4 ++-- src/funcs.c | 10 +++++----- src/init.c | 2 +- src/main.c | 13 +++++++++++++ src/protos.h | 1 + src/queue.c | 10 +++++----- 7 files changed, 28 insertions(+), 21 deletions(-) diff --git a/src/dorem.c b/src/dorem.c index 2846ed7c..bb0d8c28 100644 --- a/src/dorem.c +++ b/src/dorem.c @@ -1199,7 +1199,7 @@ int ShouldTriggerReminder(Trigger *t, TimeTrig *tim, int dse, int *err) if (DontIssueAts > 1) { /* If two or more -a options, then *DO* issue ats that are in the future */ - if (tim->ttime < SystemTime(0) / 60) { + if (tim->ttime < MinutesPastMidnight(0)) { return 0; } } else { @@ -1207,13 +1207,6 @@ int ShouldTriggerReminder(Trigger *t, TimeTrig *tim, int dse, int *err) } } - /* Don't trigger "old" timed reminders */ -/*** REMOVED... - if (dse == DSEToday && - tim->ttime != NO_TIME && - tim->ttime < SystemTime(0) / 60) return 0; - *** ...UNTIL HERE */ - /* If "infinite delta" option is chosen, always trigger future reminders */ if (InfiniteDelta || NextMode) return 1; diff --git a/src/dosubst.c b/src/dosubst.c index f326d9f9..0a82c07b 100644 --- a/src/dosubst.c +++ b/src/dosubst.c @@ -46,7 +46,7 @@ int DoSubst(ParsePtr p, DynamicBuffer *dbuf, Trigger *t, TimeTrig *tt, int dse, int mode) { int diff = dse - DSEToday; - int curtime = SystemTime(0) / 60; + int curtime = MinutesPastMidnight(0); int err, done; int c; int d, m, y; @@ -894,7 +894,7 @@ int DoSubstFromString(char const *source, DynamicBuffer *dbuf, int r; if (dse == NO_DATE) dse=DSEToday; - if (tim == NO_TIME) tim=SystemTime(0)/60; + if (tim == NO_TIME) tim=MinutesPastMidnight(0); CreateParser(source, &tempP); tempP.allownested = 0; tempTrig.typ = MSG_TYPE; diff --git a/src/funcs.c b/src/funcs.c index 3551cf27..4a9fa520 100644 --- a/src/funcs.c +++ b/src/funcs.c @@ -1421,28 +1421,28 @@ static int FRealtoday(func_info *info) static int FNow(func_info *info) { RetVal.type = TIME_TYPE; - RETVAL = (int) ( SystemTime(0) / 60L ); + RETVAL = MinutesPastMidnight(0); return OK; } static int FRealnow(func_info *info) { RetVal.type = TIME_TYPE; - RETVAL = (int) ( SystemTime(1) / 60L ); + RETVAL = MinutesPastMidnight(1); return OK; } static int FCurrent(func_info *info) { RetVal.type = DATETIME_TYPE; - RETVAL = DSEToday * MINUTES_PER_DAY + (SystemTime(0) / 60); + RETVAL = DSEToday * MINUTES_PER_DAY + MinutesPastMidnight(0); return OK; } static int FRealCurrent(func_info *info) { RetVal.type = DATETIME_TYPE; - RETVAL = RealToday * MINUTES_PER_DAY + (SystemTime(1) / 60); + RETVAL = RealToday * MINUTES_PER_DAY + MinutesPastMidnight(1); return OK; } @@ -2492,7 +2492,7 @@ static int FTimezone(func_info *info) if (Nargs == 0) { dse = DSEToday; - now = (SystemTime(0) / 60); + now = MinutesPastMidnight(0); } else { if (!HASDATE(ARG(0))) return E_BAD_TYPE; dse = DATEPART(ARG(0)); diff --git a/src/init.c b/src/init.c index 46df3045..c043f9f0 100644 --- a/src/init.c +++ b/src/init.c @@ -765,7 +765,7 @@ void InitRemind(int argc, char const *argv[]) /* Figure out the offset from UTC */ if (CalculateUTC) - (void) CalcMinsFromUTC(DSEToday, SystemTime(0)/60, + (void) CalcMinsFromUTC(DSEToday, MinutesPastMidnight(0), &MinsFromUTC, NULL); } diff --git a/src/main.c b/src/main.c index 7ba0023a..e9882996 100644 --- a/src/main.c +++ b/src/main.c @@ -760,6 +760,19 @@ long SystemTime(int realtime) (long) t->tm_sec; } +/***************************************************************/ +/* */ +/* MinutesPastMidnight */ +/* */ +/* Return the system time in minutes past midnight */ +/* */ +/***************************************************************/ +int MinutesPastMidnight(int realtime) +{ + return (int) (SystemTime(realtime) / 60); +} + + /***************************************************************/ /* */ /* SystemDate */ diff --git a/src/protos.h b/src/protos.h index bc2f6bd3..3586570d 100644 --- a/src/protos.h +++ b/src/protos.h @@ -72,6 +72,7 @@ void CreateParser (char const *s, ParsePtr p); void DestroyParser (ParsePtr p); int PushToken (char const *tok, ParsePtr p); long SystemTime (int realtime); +int MinutesPastMidnight (int realtime); int SystemDate (int *y, int *m, int *d); int DoIf (ParsePtr p); int DoElse (ParsePtr p); diff --git a/src/queue.c b/src/queue.c index 114bb9f6..9f34e583 100644 --- a/src/queue.c +++ b/src/queue.c @@ -80,7 +80,7 @@ int QueueReminder(ParsePtr p, Trigger *trig, trig->noqueue || tim->ttime == NO_TIME || trig->typ == CAL_TYPE || - tim->ttime < SystemTime(0) / 60 || + tim->ttime < MinutesPastMidnight(0) || ((trig->typ == RUN_TYPE) && RunDisabled)) return OK; qelem = NEW(QueuedRem); @@ -186,7 +186,7 @@ void HandleQueuedReminders(void) /* Initialize the queue - initialize all the entries time of issue */ while (q) { - q->tt.nexttime = (int) (SystemTime(1)/60 - 1); + q->tt.nexttime = MinutesPastMidnight(1) - 1; q->tt.nexttime = CalculateNextTime(q); q = q->next; } @@ -284,7 +284,7 @@ void HandleQueuedReminders(void) if (Daemon < 0) { printf("NOTE reminder %s", SimpleTime(q->tt.ttime)); - printf("%s", SimpleTime(SystemTime(1)/60)); + printf("%s", SimpleTime(MinutesPastMidnight(1))); if (!*DBufValue(&q->tags)) { printf("*\n"); } else { @@ -309,8 +309,8 @@ void HandleQueuedReminders(void) /* If trigger time is way in the past because computer has been suspended or hibernated, remove from queue */ if (q->tt.nexttime != NO_TIME) { - if (q->tt.ttime < (SystemTime(1)/60) - MaxLateMinutes && - q->tt.nexttime < (SystemTime(1)/60) - MaxLateMinutes) { + if (q->tt.ttime < MinutesPastMidnight(1) - MaxLateMinutes && + q->tt.nexttime < MinutesPastMidnight(1) - MaxLateMinutes) { q->tt.nexttime = NO_TIME; } }