bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: use of TZ by mktime()/strftime()


From: Andrew J. Schorr
Subject: Re: use of TZ by mktime()/strftime()
Date: Tue, 9 Aug 2022 13:49:39 -0400
User-agent: Mutt/1.5.21 (2010-09-15)

On Tue, Aug 09, 2022 at 11:18:22AM -0500, Ed Morton wrote:
> I doubt if this is a bug, but if not I'd like to understand it
> better. When I want to print the UTC time from a time saved in some
> other timezone I can do:
> 
>    $ TZ=UTC
> 
> then run `date` as:
> 
>    $ date +'%F %T' -d '2022-01-01T12:00:00 EST'
>    2022-01-01 17:00:00
> 
>    $ date +'%F %T' -d '2022-01-01T12:00:00 IST'
>    2022-01-01 06:30:00
> 
> When I try the equivalent with `gawk`, though, the results vary
> depending on which TZ value is used:
> 
>    $ awk 'BEGIN{ENVIRON["TZ"]="EST"; s=mktime("2022 01 01 12 00 00");
>    ENVIRON["TZ"]="UTC"; print strftime("%F %T",s)}'
>    2022-01-01 17:00:00
> 
>    $ awk 'BEGIN{ENVIRON["TZ"]="IST"; s=mktime("2022 01 01 12 00 00");
>    ENVIRON["TZ"]="UTC"; print strftime("%F %T",s)}'
>    2022-01-01 12:00:00
> 
> Note that the date command worked for EST and IST but the awk one
> only worked for EST. I'm using gawk 5.1.1 on both cygwin and MacOS
> and I see that effect with a few other TZ values I've tried.
> 
> What is causing awk to act on some TZ values but not others that
> date can act on? Is there any way for me to test if a given TZ will
> work in awk?

I don't think this is an awk issue. Consider:

bash-5.1$ TZ=US/Eastern date
Tue Aug  9 01:46:40 PM EDT 2022
bash-5.1$ TZ=EST date
Tue Aug  9 12:46:56 PM EST 2022
bash-5.1$ TZ=US/Pacific date
Tue Aug  9 10:46:43 AM PDT 2022
bash-5.1$ TZ=PDT date
Tue Aug  9 05:47:48 PM PDT 2022
bash-5.1$ TZ=UTC date
Tue Aug  9 05:46:58 PM UTC 2022
bash-5.1$ TZ=IST date
Tue Aug  9 05:47:00 PM IST 2022

It seems that "date -d" can grok some time zone names that don't work
when set in the TZ environment variable.

Regards,
Andy



reply via email to

[Prev in Thread] Current Thread [Next in Thread]