From 4237dc4a3f2b4929f6bc3d88f517e3c8f64a48c2 Mon Sep 17 00:00:00 2001 From: Dianne Skoll Date: Thu, 4 Sep 2025 10:09:46 -0400 Subject: [PATCH] Allow empty string to be used in tzconvert to designate system default time zone. --- man/remind.1.in | 12 +++++++----- src/funcs.c | 5 ++++- tests/test-timezone-support | 9 +++++++++ tests/tz.cmp | 7 +++++++ 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/man/remind.1.in b/man/remind.1.in index 4b4ffaaa..d4ae1c99 100644 --- a/man/remind.1.in +++ b/man/remind.1.in @@ -4928,11 +4928,13 @@ command can never be triggered: Returns "STRING", "INT", "DATE", "TIME" or "DATETIME", depending on the type of \fIarg\fR. .TP .B tzconvert(q_datetime, s_srczone [,s_dstzone]) -Converts \fBdatetime\fR from the time zone named by \fBsrczone\fR to the -time zone named by \fBdstzone\fR. If \fBdstzone\fR is omitted, the -default system time zone is used. The return value is a DATETIME. Time -zone names are system-dependent; consult your operating system for legal -values. Here is an example: +Converts \fBdatetime\fR from the time zone named by \fBsrczone\fR to +the time zone named by \fBdstzone\fR. If \fBsrczone\fR is the empty +string, then the default system time zone is used as the source zone. +If \fBdstzone\fR is omitted or is the empty string, the default system +time zone is used as the destination zone. The return value is a +DATETIME. Time zone names are system-dependent; consult your +operating system for legal values. Here is an example: .PP .nf tzconvert('2007-07-08@01:14', "Canada/Eastern", "Canada/Pacific") diff --git a/src/funcs.c b/src/funcs.c index a93a11c4..2dec229a 100644 --- a/src/funcs.c +++ b/src/funcs.c @@ -3928,9 +3928,12 @@ int tz_convert(int year, int month, int day, old_tz = StrDup(old_tz); if (!old_tz) return E_NO_MEM; } - if (tgt_tz == NULL) { + if (tgt_tz == NULL || !*tgt_tz) { tgt_tz = old_tz; } + if (src_tz == NULL || !*src_tz) { + src_tz = old_tz; + } /* set source TZ */ r = tz_set_tz(src_tz); diff --git a/tests/test-timezone-support b/tests/test-timezone-support index 6e59b9a8..54f2b675 100755 --- a/tests/test-timezone-support +++ b/tests/test-timezone-support @@ -101,6 +101,15 @@ REM AT 13:33 TZ "" TZ America/Los_Angeles MSG Whatsup? %*l %3. REM TZ Universal MSG Borked EOF +TZ=America/Toronto $REMIND -dx - <<'EOF' >> $OUT 2>&1 +SET a tzconvert('2025-09-01@14:44', "", "Europe/Berlin") +SET a tzconvert('2025-09-01@14:44', "America/Toronto", "Europe/Berlin") +SET a tzconvert('2025-09-01@14:44', "Europe/Berlin", "") +SET a tzconvert('2025-09-01@14:44', "Europe/Berlin") +SET a tzconvert('2025-09-01@14:44', "", "") +SET a tzconvert('2025-09-01@14:44', "") +EOF + cmp -s $OUT $CMP if [ "$?" = "0" ] ; then echo "Remind: Time zone test PASSED" diff --git a/tests/tz.cmp b/tests/tz.cmp index cad863ec..2064d23b 100644 --- a/tests/tz.cmp +++ b/tests/tz.cmp @@ -31,3 +31,10 @@ Whatsup? today at 13:33. -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.