mirror of
https://salsa.debian.org/dskoll/remind.git
synced 2026-04-16 06:18:47 +02:00
More work on timezone support.
This commit is contained in:
39
src/dorem.c
39
src/dorem.c
@@ -46,14 +46,18 @@ static void ExitTimezone(char const *tz)
|
||||
/* Nothing to do */
|
||||
return;
|
||||
}
|
||||
/* Revert to our local time zone */
|
||||
(void) tz_set_tz(LocalTimeZone);
|
||||
|
||||
DSEToday = LocalDSEToday;
|
||||
SysTime = LocalSysTime;
|
||||
FromDSE(DSEToday, &CurYear, &CurMon, &CurDay);
|
||||
|
||||
if (DebugFlag & DB_SWITCH_ZONE) {
|
||||
fprintf(stderr, "TZ exit %s: %04d-%02d-%02d %02d:%02d\n", tz,
|
||||
CurYear, CurMon+1, CurDay, SysTime / 60, SysTime % 60);
|
||||
CurYear, CurMon+1, CurDay, SysTime / 3600, (SysTime/60) % 60);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -77,8 +81,8 @@ static void EnterTimezone(char const *tz)
|
||||
|
||||
FromDSE(LocalDSEToday, &y, &m, &d);
|
||||
tm.tm_sec = 0;
|
||||
tm.tm_min = LocalSysTime % 60;
|
||||
tm.tm_hour = LocalSysTime / 60;
|
||||
tm.tm_min = (LocalSysTime/60) % 60;
|
||||
tm.tm_hour = LocalSysTime / 3600;
|
||||
tm.tm_mday = d;
|
||||
tm.tm_mon = m;
|
||||
tm.tm_year = y - 1900;
|
||||
@@ -98,11 +102,11 @@ static void EnterTimezone(char const *tz)
|
||||
CurMon = tm.tm_mon;
|
||||
CurYear = tm.tm_year + 1900;
|
||||
DSEToday = DSE(CurYear, CurMon, CurDay);
|
||||
SysTime = tm.tm_min + (tm.tm_hour * 60);
|
||||
SysTime = tm.tm_min * 60 + (tm.tm_hour * 3600);
|
||||
|
||||
if (DebugFlag & DB_SWITCH_ZONE) {
|
||||
fprintf(stderr, "TZ enter %s: %04d-%02d-%02d %02d:%02d\n", tz,
|
||||
CurYear, CurMon+1, CurDay, SysTime / 60, SysTime % 60);
|
||||
CurYear, CurMon+1, CurDay, SysTime / 3600, (SysTime/60) % 60);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -361,6 +365,12 @@ int DoRem(ParsePtr p)
|
||||
return r;
|
||||
}
|
||||
|
||||
if (trig.tz != NULL && tim.ttime == NO_TIME) {
|
||||
PurgeEchoLine("%s\n", CurLine);
|
||||
FreeTrig(&trig);
|
||||
return E_TZ_NO_AT;
|
||||
}
|
||||
|
||||
if (trig.complete_through != NO_DATE && !trig.is_todo) {
|
||||
PurgeEchoLine("%s\n", CurLine);
|
||||
FreeTrig(&trig);
|
||||
@@ -446,7 +456,9 @@ int DoRem(ParsePtr p)
|
||||
}
|
||||
} else {
|
||||
/* Calculate the trigger date */
|
||||
EnterTimezone(trig.tz);
|
||||
dse = ComputeTrigger(get_scanfrom(&trig), &trig, &tim, &r, 1);
|
||||
ExitTimezone(trig.tz);
|
||||
if (r) {
|
||||
if (PurgeMode) {
|
||||
if (!Hush) {
|
||||
@@ -752,6 +764,7 @@ int ParseRem(ParsePtr s, Trigger *trig, TimeTrig *tim)
|
||||
trig->complete_through = NO_DATE;
|
||||
trig->adj_for_last = 0;
|
||||
trig->infos = NULL;
|
||||
trig->tz = NULL;
|
||||
|
||||
int parsing = 1;
|
||||
while(parsing) {
|
||||
@@ -1025,6 +1038,22 @@ int ParseRem(ParsePtr s, Trigger *trig, TimeTrig *tim)
|
||||
DBufFree(&buf);
|
||||
break;
|
||||
|
||||
case T_Tz:
|
||||
if (trig->tz) {
|
||||
return E_TZ_SPECIFIED_TWICE;
|
||||
}
|
||||
|
||||
r = ParseQuotedString(s, &buf);
|
||||
if (r != OK) {
|
||||
return r;
|
||||
}
|
||||
trig->tz = StrDup(DBufValue(&buf));
|
||||
if (!trig->tz) {
|
||||
return E_NO_MEM;
|
||||
}
|
||||
DBufFree(&buf);
|
||||
break;
|
||||
|
||||
case T_Info:
|
||||
r = ParseQuotedString(s, &buf);
|
||||
if (r != OK) {
|
||||
|
||||
@@ -132,6 +132,8 @@
|
||||
#define E_COMPLETE_WITHOUT_TODO 108
|
||||
#define E_MAX_OVERDUE_TWICE 109
|
||||
#define E_MAX_OVERDUE_WITHOUT_TODO 110
|
||||
#define E_TZ_SPECIFIED_TWICE 111
|
||||
#define E_TZ_NO_AT 112
|
||||
|
||||
#ifdef MK_GLOBALS
|
||||
#undef EXTERN
|
||||
@@ -261,6 +263,8 @@ EXTERN char *ErrMsg[]
|
||||
/* E_COMPLETE_WITHOUT_TODO */ "COMPLETE-THROUGH specified without TODO",
|
||||
/* E_MAX_OVERDUE_TWICE */ "MAX-OVERDUE specified twice",
|
||||
/* E_MAX_OVERDUE_WITHOUT_TODO */ "MAX-OVERDUE specified without TODO",
|
||||
/* E_TZ_SPECIFIED_TWICE */ "TZ specified twice",
|
||||
/* E_TZ_NO_AT */ "TZ specified for non-timed reminder",
|
||||
}
|
||||
#endif /* MK_GLOBALS */
|
||||
;
|
||||
|
||||
@@ -231,6 +231,7 @@ void InitRemind(int argc, char const *argv[])
|
||||
fprintf(ErrFp, "\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
LocalSysTime = SystemTime(0);
|
||||
DSEToday = RealToday;
|
||||
LocalDSEToday = DSEToday;
|
||||
FromDSE(DSEToday, &CurYear, &CurMon, &CurDay);
|
||||
|
||||
@@ -2044,6 +2044,10 @@ FreeTrig(Trigger *t)
|
||||
if (t->infos) {
|
||||
FreeTrigInfoChain(t->infos);
|
||||
}
|
||||
if (t->tz) {
|
||||
free(t->tz);
|
||||
}
|
||||
t->tz = NULL;
|
||||
t->infos = NULL;
|
||||
}
|
||||
|
||||
@@ -2074,6 +2078,7 @@ ClearLastTriggers(void)
|
||||
LastTrigger.complete_through = NO_DATE;
|
||||
LastTrigger.max_overdue = -1;
|
||||
FreeTrig(&LastTrigger);
|
||||
|
||||
LastTimeTrig.ttime = NO_TIME;
|
||||
LastTimeTrig.delta = NO_DELTA;
|
||||
LastTimeTrig.rep = NO_REP;
|
||||
@@ -2103,6 +2108,9 @@ SaveLastTrigger(Trigger const *t)
|
||||
LastTrigger.infos = NULL;
|
||||
DBufInit(&(LastTrigger.tags));
|
||||
|
||||
if (LastTrigger.tz) {
|
||||
LastTrigger.tz = StrDup(LastTrigger.tz);
|
||||
}
|
||||
DBufPuts(&(LastTrigger.tags), DBufValue(&(t->tags)));
|
||||
TrigInfo *cur = t->infos;
|
||||
while(cur) {
|
||||
|
||||
@@ -123,6 +123,7 @@ Token TokArray[] = {
|
||||
{ "todo", 4, T_Todo, 0 },
|
||||
{ "translate", 5, T_Translate, 0 },
|
||||
{ "tuesday", 3, T_WkDay, 1 },
|
||||
{ "tz", 2, T_Tz, 0 },
|
||||
{ "unset", 5, T_UnSet, 0 },
|
||||
{ "until", 5, T_Until, 0 },
|
||||
{ "warn", 4, T_Warn, 0 },
|
||||
|
||||
@@ -152,6 +152,7 @@ typedef struct {
|
||||
DynamicBuffer tags;
|
||||
char passthru[PASSTHRU_LEN+1];
|
||||
TrigInfo *infos;
|
||||
char const *tz; /* Time Zone */
|
||||
} Trigger;
|
||||
|
||||
/* A time trigger */
|
||||
@@ -240,8 +241,8 @@ enum TokTypes
|
||||
T_Omit, T_OmitFunc, T_Once, T_Ordinal, T_Pop, T_PopFuncs, T_PopVars,
|
||||
T_Preserve, T_Priority, T_Push, T_PushFuncs, T_PushVars, T_Rem,
|
||||
T_RemType, T_Rep, T_Return, T_Scanfrom, T_Sched, T_Set, T_Skip, T_Tag,
|
||||
T_Through, T_Time, T_Todo, T_Translate, T_UnSet, T_Until, T_Warn, T_WkDay,
|
||||
T_Year
|
||||
T_Through, T_Time, T_Todo, T_Translate, T_Tz, T_UnSet, T_Until, T_Warn,
|
||||
T_WkDay, T_Year,
|
||||
};
|
||||
|
||||
/* The structure of a token */
|
||||
|
||||
Reference in New Issue
Block a user