zsh-users
 help / color / mirror / code / Atom feed
* Timezones and print -P %D
@ 2020-11-12 19:38 Clinton Bunch
  2020-11-13  4:06 ` Phil Pennock
  0 siblings, 1 reply; 2+ messages in thread
From: Clinton Bunch @ 2020-11-12 19:38 UTC (permalink / raw)
  To: zsh-users

Can someone explain what's going on here?  I was under the impression 
that variable assignments on the command-line were exported to the 
environment and only effective for the life of the command.

cdblinux[~]% unset TZ
cdblinux[~]% print -P '%D{%Y-%m-%dT%H:%M%z}'
2020-11-12T13:32-0600
cdblinux[~]% TZ=UTC print -P '%D{%Y-%m-%dT%H:%M%z}'
2020-11-12T13:33-0600
cdblinux[~]% export TZ
cdblinux[~]% TZ=UTC print -P '%D{%Y-%m-%dT%H:%M%z}'
2020-11-12T19:33+0000
cdblinux[~]% print -P '%D{%Y-%m-%dT%H:%M%z}'
2020-11-12T19:33+0000
cdblinux[~]% unset TZ
cdblinux[~]% print -P '%D{%Y-%m-%dT%H:%M%z}'
2020-11-12T13:33-0600
cdblinux[~]% cat /etc/system-release
CentOS Linux release 8.2.2004 (Core)
cdblinux[~]% uname -a
Linux cdblinux.cfhp.com 4.18.0-193.14.2.el8_2.x86_64 #1 SMP Sun Jul 26 
03:54:29 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
cdblinux[~]% echo $ZSH_VERSION
5.5.1



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Timezones and print -P %D
  2020-11-12 19:38 Timezones and print -P %D Clinton Bunch
@ 2020-11-13  4:06 ` Phil Pennock
  0 siblings, 0 replies; 2+ messages in thread
From: Phil Pennock @ 2020-11-13  4:06 UTC (permalink / raw)
  To: Clinton Bunch; +Cc: zsh-users

On 2020-11-12 at 13:38 -0600, Clinton Bunch wrote:
> Can someone explain what's going on here?  I was under the impression that
> variable assignments on the command-line were exported to the environment
> and only effective for the life of the command.
> 
> cdblinux[~]% unset TZ
> cdblinux[~]% print -P '%D{%Y-%m-%dT%H:%M%z}'
> 2020-11-12T13:32-0600

At this point, try something like:

  ls -l /etc/localtime
  sudo rm /etc/localtime
  print -P '%D{%Y-%m-%dT%H:%M%z}'
  sudo ln -sv $WhateverItWasBefore /etc/localtime

The key is that TZ is an override for "the time in the system timezone",
not for "the time in UTC".  This is not Zsh but is probably somewhere in
POSIX.

> cdblinux[~]% TZ=UTC print -P '%D{%Y-%m-%dT%H:%M%z}'
> 2020-11-12T13:33-0600

This one confuses me.  This, I would have expected to work without
needing to explicitly export TZ first.  I think this might be a zsh bug.

> cdblinux[~]% export TZ
> cdblinux[~]% TZ=UTC print -P '%D{%Y-%m-%dT%H:%M%z}'
> 2020-11-12T19:33+0000
> cdblinux[~]% print -P '%D{%Y-%m-%dT%H:%M%z}'
> 2020-11-12T19:33+0000

The presence of $TZ in the environment overrides use of /etc/localtime;
if it's empty, that's UTC.

> cdblinux[~]% unset TZ
> cdblinux[~]% print -P '%D{%Y-%m-%dT%H:%M%z}'
> 2020-11-12T13:33-0600

And you're back to /etc/localtime

-Phil


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-11-13  4:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-12 19:38 Timezones and print -P %D Clinton Bunch
2020-11-13  4:06 ` Phil Pennock

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).