Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Builtin strftime and TZ assignments
- X-seq: zsh-workers 34596
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: Builtin strftime and TZ assignments
- Date: Sat, 21 Feb 2015 12:45:46 -0800
- In-reply-to: <150221102305.ZM26540@torch.brasslantern.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <CADjGqHvaOkB-T_qGHDvt9=8TzSGiR8-FptXCX8VNFyfPkmJN-g@mail.gmail.com> <CABx2=D9e8KPMd9fxL5UY5BoVOdnNyMx-d2tR3v_4Gmd7V5m7DQ@mail.gmail.com> <150221102305.ZM26540@torch.brasslantern.com>
On Feb 21, 10:23am, Bart Schaefer wrote:
} Subject: Re: Convert UTC time to local time using strftime and zsh/datetime
}
} On Feb 20, 9:02pm, Kurtis Rader wrote:
} }
} } TZ=UTC strftime -r "%Y-%m-%d %H:%M:%S +0000" "2015-02-11 16:42:30 +0000"
}
} The next question is whether the strftime builtin should implicitly
} perform "local -x TZ" to make Kurtis' example do the expected thing.
So the patch below does this if we want it. It also has the side-effect
that the builtin strftime respects an otherwise not-exported $TZ, which
may or may not be desirable.
However, I'm hoping someone (PWS?) can explain why the extra pm->level
bump is necessary to get the parameter to be removed from the environment
upon endparamscope().
diff --git a/Src/Modules/datetime.c b/Src/Modules/datetime.c
index 00ebd2b..15edfc8 100644
--- a/Src/Modules/datetime.c
+++ b/Src/Modules/datetime.c
@@ -94,7 +94,7 @@ reverse_strftime(char *nam, char **argv, char *scalar, int quiet)
}
static int
-bin_strftime(char *nam, char **argv, Options ops, UNUSED(int func))
+output_strftime(char *nam, char **argv, Options ops, UNUSED(int func))
{
int bufsize, x;
char *endptr = NULL, *scalar = NULL, *buffer;
@@ -145,6 +145,27 @@ bin_strftime(char *nam, char **argv, Options ops, UNUSED(int func))
return 0;
}
+static int
+bin_strftime(char *nam, char **argv, Options ops, int func)
+{
+ int result = 1;
+ char *tz = getsparam("TZ");
+
+ startparamscope();
+ if (tz && *tz) {
+ Param pm = createparam("TZ", PM_LOCAL|PM_SCALAR|PM_EXPORTED);
+ if (pm) {
+ /* Why is this needed inside startparamscope()? */
+ pm->level = locallevel + 1; /* copied from Zle/zle_params.c */
+ }
+ setsparam("TZ", ztrdup(tz));
+ }
+ result = output_strftime(nam, argv, ops, func);
+ endparamscope();
+
+ return result;
+}
+
static zlong
getcurrentsecs(UNUSED(Param pm))
{
--
Barton E. Schaefer
Messages sorted by:
Reverse Date,
Date,
Thread,
Author