zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Zsh-Users List <zsh-users@zsh.org>
Subject: Re: Convert UTC time to local time using strftime and zsh/datetime
Date: Sat, 21 Feb 2015 10:23:05 -0800	[thread overview]
Message-ID: <150221102305.ZM26540@torch.brasslantern.com> (raw)
In-Reply-To: <CABx2=D9e8KPMd9fxL5UY5BoVOdnNyMx-d2tR3v_4Gmd7V5m7DQ@mail.gmail.com>

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"
} 
} Which should yield 1423672950 as the seconds since the UNIX epoch.

Except it doesn't unless you have already done "export TZ", because
strftime is not one of the special builtins that really do alter the
process environment when you prefix them with a variable assignment.
So in my environment where TZ starts out not set, this still returns
the epoch in my local time zone, e.g. 1423701750.

This is guaranteed to fix the timezone issue:

    (){ local -x TZ=UTC;
	strftime -r "%Y-%m-%d %H:%M:%S %z" "2015-02-11 16:42:30 +0000" }

but note that %z to match the timezone is a glibc extension to strptime
and may not work everywhere.

Also note that strptime is not defined to perform timezone conversions;
even though glibc strptime can be told that a timezone is present, it
parses it and then throws it away.  In TJ's original formulation

} > > strftime -r "%Y-%m-%d %H:%M:%S +0000" "2015-02-11 16:42:30 +0000"

the +0000 is just a string which is matched but ignored.  Either way,
this is why the TZ=UTC environment setting is needed.

The next question is whether the strftime builtin should implicitly
perform "local -x TZ" to make Kurtis' example do the expected thing.


      reply	other threads:[~2015-02-21 18:23 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-21  4:41 TJ Luoma
2015-02-21  5:02 ` Kurtis Rader
2015-02-21 18:23   ` Bart Schaefer [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=150221102305.ZM26540@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).