From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14381 invoked by alias); 28 Apr 2012 21:11:17 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 17032 Received: (qmail 26287 invoked from network); 28 Apr 2012 21:11:05 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham version=3.3.2 Received-SPF: pass (ns1.primenet.com.au: SPF record at benizi.com designates 64.130.10.15 as permitted sender) Date: Sat, 28 Apr 2012 17:10:38 -0400 (EDT) From: "Benjamin R. Haskell" To: TJ Luoma cc: zsh-users@zsh.org Subject: Re: can strftime show 'p.m.' instead of 'PM'? In-Reply-To: <29B9CC7BDEB94DA784265196AE5C7EEE@gmail.com> Message-ID: References: <29B9CC7BDEB94DA784265196AE5C7EEE@gmail.com> User-Agent: Alpine 2.01 (LNX 1266 2009-07-14) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; format=flowed; charset=US-ASCII On Sat, 28 Apr 2012, TJ Luoma wrote: > > Before I begin, I should say that I realize this may (seem to) be > extremely picayune, but it consistently annoys me. Judge me as you > will :-) > > `man strftime` says this: > > %p is replaced by national representation of either "ante meridiem" (a.m.) or "post meridiem" (p.m.) as appropriate. > > %F is equivalent to ``%Y-%m-%d''. > > %r is equivalent to ``%I:%M:%S %p''. My `man strftime` lists: %p Either "AM" or "PM" according to the given time value, or the corresponding strings for the current locale. Noon is treated as "PM" and midnight as "AM". %P Like %p but in lowercase: "am" or "pm" or a corresponding string for the current locale. (GNU) AFAIK, the strftime provided by zsh/datetime just passes its format string to the C library function. (So, right now, %p and %P get me 'PM' and 'pm', respectively.) > However when I do this in zsh > > $ strftime "%F %r" "$EPOCHSECONDS" > > I get this: > > 2012-04-28 02:50:24 PM > > Ideally I would like "PM" to be "p.m." but I'd probably settle for "pm" > > I tried using '%P' instead of '%p' (thinking that might invert the case) but that just gave me a literal 'P' instead. > > I realize that I could use: > > strftime "%F %r" "$EPOCHSECONDS" | tr '[A-Z]' '[a-z]' > > or even > > strftime "%F %r" "$EPOCHSECONDS" | sed 's#AM#a.m#g; s#pPM#p.m.#g' > > but I wondered if there was a better (more efficient) way. Since it's system-dependent, you're probably better off munging it yourself. But if you're extremely worried about efficiency, you don't need to pipe to `tr` or `sed` (so you can avoid launching an external process): print -r - ${${${:-"$(strftime "%F %r" "$EPOCHSECONDS")"}/AM/a.m.}/PM/p.m.} -- Best, Ben