Add trigimetz and trigeventstarttz functions.

This commit is contained in:
Dianne Skoll
2025-09-04 15:36:27 -04:00
parent e449fcdfcf
commit ef7021972e
7 changed files with 108 additions and 23 deletions

View File

@@ -179,9 +179,9 @@
"realtoday" "rows" "sgn" "shell" "shellescape" "slide" "soleq"
"stdout" "strlen" "substr" "sunrise" "sunset" "time" "timepart"
"timezone" "today" "trig" "trigback" "trigbase" "trigcompletethrough" "trigdate" "trigdatetime"
"trigdelta" "trigduration" "trigeventduration" "trigeventstart"
"trigdelta" "trigduration" "trigeventduration" "trigeventstart" "trigeventstarttz"
"trigfrom" "trigger" "triginfo" "trigistodo" "trigmaxoverdue" "trigpriority" "trigrep"
"trigscanfrom" "trigtags" "trigtime" "trigtimedelta" "trigtimerep" "trigtz"
"trigscanfrom" "trigtags" "trigtime" "trigtimedelta" "trigtimerep" "trigtimetz" "trigtz"
"triguntil" "trigvalid" "typeof" "tzconvert" "upper" "utctolocal"
"value" "version" "weekno" "wkday" "wkdaynum" "year"
)

View File

@@ -4753,6 +4753,11 @@ have an \fBAT\fR clause, returns the integer -1 (and differs from
\fBtrigdatetime()\fR in this respect.) See "MULTI-DAY EVENTS" for more
information.
.TP
.B trigeventstarttz()
Similar to \fBtrigeventstart()\fR but returns the DATETIME in the time
zone specified by a TZ clause, if one was present. If no TZ clause
was present, returns the same value as \fBtrigeventstart()\fR.
.TP
.B trigeventduration()
Returns a \fBTIME\fR representing the duration of the most recent
triggerable \fBREM\fR command that had an \fBAT\fR and a
@@ -4907,11 +4912,16 @@ were no TAGs. If there are multiple tags, they are each separated by
a single comma, not a comma and a space.
.TP
.B trigtime()
Returns the time of the last \fBREM\fR command with an \fBAT\fR
clause. If the last \fBREM\fR did not have an \fBAT\fR clause,
returns the integer 0. If a \fBREM\fR command has an \fBAT\fR clause
with a \fBDURATION\fR, then you can compute the end time as
\fBtrigtime() + trigduration()\fR.
Returns the time of the last \fBREM\fR command with an \fBAT\fR clause
\fIin the system default time zone\fR. If the last \fBREM\fR did not
have an \fBAT\fR clause, returns the integer 0. If a \fBREM\fR
command has an \fBAT\fR clause with a \fBDURATION\fR, then you can
compute the end time as \fBtrigtime() + trigduration()\fR.
.TP
.B trigtimetz()
Similar to \fBtrigtime()\fR but returns the time in the time zone specified
by a TZ clause, if one was present. If no TZ clause was present, returns
the same value as \fBtrigtime()\fR.
.TP
.B trigvalid()
Returns 1 if the value returned by \fBtrigdate()\fR is valid for the most

View File

@@ -56,9 +56,9 @@ int AdjustTriggerForTimeZone(Trigger *trig, int dse, TimeTrig *tim)
dse = DSE(tm.tm_year+1900, tm.tm_mon, tm.tm_mday);
tim->ttime = tm.tm_hour * 60 + tm.tm_min;
SaveAllTriggerInfo(trig, tim, dse, tim->ttime, 1);
/* Adjust eventstart also */
trig->eventstart = dse * MINUTES_PER_DAY + tim->ttime;
SaveAllTriggerInfo(trig, tim, dse, tim->ttime, 1);
if (DebugFlag & DB_PRTTRIG) {
fprintf(ErrFp, "%s(%s): Trig(tz_adj %s) = %s, %d %s, %d AT %02d:%02d",
GetCurrentFilename(), line_range(LineNoStart, LineNo), trig->tz,

View File

@@ -181,6 +181,7 @@ static int FTrigduration (func_info *);
static int FTriginfo (func_info *);
static int FTrigeventduration(func_info *);
static int FTrigeventstart (func_info *);
static int FTrigeventstarttz (func_info *);
static int FTrigfrom (func_info *);
static int FTrigger (func_info *);
static int FTrigistodo (func_info *);
@@ -190,6 +191,7 @@ static int FTrigrep (func_info *);
static int FTrigscanfrom (func_info *);
static int FTrigtags (func_info *);
static int FTrigtime (func_info *);
static int FTrigtimetz (func_info *);
static int FTrigtimedelta (func_info *);
static int FTrigtimerep (func_info *);
static int FTrigtz (func_info *);
@@ -357,6 +359,7 @@ BuiltinFunc Func[] = {
{ "trigduration", 0, 0, 0, FTrigduration, NULL },
{ "trigeventduration", 0, 0, 0, FTrigeventduration, NULL },
{ "trigeventstart", 0, 0, 0, FTrigeventstart, NULL },
{ "trigeventstarttz", 0, 0, 0, FTrigeventstarttz, NULL },
{ "trigfrom", 0, 0, 0, FTrigfrom, NULL },
{ "trigger", 1, 3, 0, FTrigger, NULL },
{ "triginfo", 1, 1, 0, FTriginfo, NULL },
@@ -369,6 +372,7 @@ BuiltinFunc Func[] = {
{ "trigtime", 0, 0, 0, FTrigtime, NULL },
{ "trigtimedelta",0, 0, 0, FTrigtimedelta, NULL },
{ "trigtimerep", 0, 0, 0, FTrigtimerep, NULL },
{ "trigtimetz", 0, 0, 0, FTrigtimetz, NULL },
{ "trigtz", 0, 0, 0, FTrigtz, NULL },
{ "triguntil", 0, 0, 0, FTriguntil, NULL },
{ "trigvalid", 0, 0, 0, FTrigvalid, NULL },
@@ -2000,6 +2004,22 @@ static int FTrigeventstart(func_info *info)
return OK;
}
static int FTrigeventstarttz(func_info *info)
{
if (LastTrigger.eventstart == NO_TIME) {
RetVal.type = INT_TYPE;
RETVAL = -1;
} else {
RetVal.type = DATETIME_TYPE;
if (LastTrigger.eventstart_orig != NO_TIME) {
RETVAL = LastTrigger.eventstart_orig;
} else {
RETVAL = LastTrigger.eventstart;
}
}
return OK;
}
static int FTrigduration(func_info *info)
{
if (LastTimeTrig.duration == NO_TIME) {
@@ -2086,6 +2106,22 @@ static int FTrigtime(func_info *info)
return OK;
}
static int FTrigtimetz(func_info *info)
{
if (LastTriggerTime != NO_TIME) {
RetVal.type = TIME_TYPE;
if (LastTimeTrig.ttime_orig != NO_TIME) {
RETVAL = LastTimeTrig.ttime_orig;
} else {
RETVAL = LastTriggerTime;
}
} else {
RetVal.type = INT_TYPE;
RETVAL = 0;
}
return OK;
}
static int FTrigdatetime(func_info *info)
{
if (!LastTrigValid) {

View File

@@ -20,7 +20,7 @@ fi
# ../src/remind. This trick was suggested by Jochen Sprickerhof
alias remind="echo You should be using ../src/remind explicitly in test-rem >&2; exit 1"
REMIND="../src/remind -q --flush"
REMIND="../src/remind -h -q --flush"
OUT=../tests/tz.out
CMP=../tests/tz.cmp
@@ -30,20 +30,30 @@ TZ=Europe/Amsterdam $REMIND - 2025-09-03@14:00 <<'EOF' >> $OUT 2>&1
SET $AddBlankLines=0
BANNER %
REM Fri AT 23:30 TZ America/Toronto +1000 SATISFY [$Td == 13] MSG Fri 13th @23:30 Eastern is %a %2 here
DEBUG +x
SET a $T
SET b $Tt
set c trigtz()
MSG a = [a], b = [b], c = [c]
SET c trigtz()
SET d trigtime()
SET e trigtimetz()
SET f trigeventstart()
SET g trigeventstarttz()
DEBUG -x
EOF
TZ=Europe/Amsterdam $REMIND - 2026-02-14@14:00 <<'EOF' >> $OUT 2>&1
SET $AddBlankLines=0
BANNER %
REM Fri AT 23:30 TZ America/Toronto +1000 SATISFY [$Td == 13] MSG Fri 13th @23:30 Eastern is %a %2 here
DEBUG +x
SET a $T
SET b $Tt
set c trigtz()
MSG a = [a], b = [b], c = [c]
SET c trigtz()
SET d trigtime()
SET e trigtimetz()
SET f trigeventstart()
SET g trigeventstarttz()
DEBUG -x
EOF
TZ=Europe/Amsterdam $REMIND - 2026-02-15@14:00 <<'EOF' >> $OUT 2>&1
@@ -52,7 +62,11 @@ BANNER %
REM Fri AT 23:30 TZ America/Toronto +1000 SATISFY [$Td == 13] MSG Fri 13th @23:30 Eastern is %a %2 here
SET a $T
SET b $Tt
MSG a = [a], b = [b]
SET c trigtz()
SET d trigtime()
SET e trigtimetz()
SET f trigeventstart()
SET g trigeventstarttz()
EOF
TZ=America/Toronto $REMIND -p12 - 2025-01-01 <<'EOF' 2>&1 | grep Locally >> $OUT 2>&1
@@ -68,8 +82,15 @@ SET full '2026-01-03@05:04'
SET last '2026-01-10@10:49'
REM [new] +100 MSG New Moon %*l %3.
SET a trigtz()
REM MSG trigtz = [a]
SET b trigtime()
SET c trigtimetz()
SET d trigeventstart()
SET e trigeventstarttz()
REM MSG trigtz = [a], trigtime = [b], trigtimetz = [c], trigeventstart = [d], trigeventstarttz = [e]
REM [first] +100 MSG First Quarter %*l %3.
REM [full] +100 MSG Full Moon %*l %3.
REM [last] +100 MSG Last Quarter %*l %3.
@@ -80,8 +101,15 @@ SET full tzconvert(full, "America/Toronto", "Australia/Sydney")
SET last tzconvert(last, "America/Toronto", "Australia/Sydney")
REM [new] +100 TZ Australia/Sydney MSG New Moon %*l %3. (*)
SET a trigtz()
REM MSG trigtz = [a]
SET b trigtime()
SET c trigtimetz()
SET d trigeventstart()
SET e trigeventstarttz()
REM MSG trigtz = [a], trigtime = [b], trigtimetz = [c], trigeventstart = [d], trigeventstarttz = [e]
REM [first] +100 TZ Australia/Sydney MSG First Quarter %*l %3. (*)
REM [full] +100 TZ Australia/Sydney MSG Full Moon %*l %3. (*)
REM [last] +100 TZ Australia/Sydney MSG Last Quarter %*l %3. (*)

View File

@@ -24643,6 +24643,7 @@ trigdelta
trigduration
trigeventduration
trigeventstart
trigeventstarttz
trigfrom
trigger
triginfo
@@ -24655,6 +24656,7 @@ trigtags
trigtime
trigtimedelta
trigtimerep
trigtimetz
trigtz
triguntil
trigvalid

View File

@@ -1,9 +1,20 @@
Fri 13th @23:30 Eastern is on Saturday, 14 February, 2026 at 5:30am here
a = 2026-02-14, b = 05:30, c = America/Toronto
$T => 2026-02-14
$Tt => 05:30
trigtz() => "America/Toronto"
trigtime() => 05:30
trigtimetz() => 23:30
trigeventstart() => 2026-02-14@05:30
trigeventstarttz() => 2026-02-13@23:30
Fri 13th @23:30 Eastern is today at 5:30am here
a = 2026-02-14, b = 05:30, c = America/Toronto
$T => 2026-02-14
$Tt => 05:30
trigtz() => "America/Toronto"
trigtime() => 05:30
trigtimetz() => 23:30
trigeventstart() => 2026-02-14@05:30
trigeventstarttz() => 2026-02-13@23:30
Fri 13th @23:30 Eastern is on Saturday, 14 March, 2026 at 4:30am here
a = 2026-03-14, b = 04:30
2025/01/09 * * * 540 9:00am Locally: at 09:00
2025/02/13 * * * 540 9:00am Locally: at 09:00
2025/03/13 * * * 600 10:00am Locally: at 10:00
@@ -16,8 +27,8 @@ a = 2026-03-14, b = 04:30
2025/10/09 * * * 540 9:00am Locally: at 09:00
2025/11/13 * * * 540 9:00am Locally: at 09:00
2025/12/11 * * * 540 9:00am Locally: at 09:00
trigtz =
trigtz = Australia/Sydney
trigtz = , trigtime = 14:53, trigtimetz = 14:53, trigeventstart = 2026-01-18@14:53, trigeventstarttz = 2026-01-18@14:53
trigtz = Australia/Sydney, trigtime = 14:53, trigtimetz = 06:53, trigeventstart = 2026-01-18@14:53, trigeventstarttz = 2026-01-19@06:53
new=2026-01-19@06:53 first=2026-01-26@15:48 full=2026-01-03@21:04 last=2026-01-11@02:49
Full Moon 2026-01-03 at 05:04.
Full Moon 2026-01-03 at 05:04. (*)
@@ -32,11 +43,9 @@ Whatsup? today at 13:33.
-stdin-(4): TZ specified twice
-stdin-(5): TZ specified twice
-stdin-(6): TZ specified for non-timed reminder
No reminders.
tzconvert(2025-09-01@14:44, "", "Europe/Berlin") => 2025-09-01@20:44
tzconvert(2025-09-01@14:44, "America/Toronto", "Europe/Berlin") => 2025-09-01@20:44
tzconvert(2025-09-01@14:44, "Europe/Berlin", "") => 2025-09-01@08:44
tzconvert(2025-09-01@14:44, "Europe/Berlin") => 2025-09-01@08:44
tzconvert(2025-09-01@14:44, "", "") => 2025-09-01@14:44
tzconvert(2025-09-01@14:44, "") => 2025-09-01@14:44
No reminders.