Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Timezones and print -P %D



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




Messages sorted by: Reverse Date, Date, Thread, Author