zsh-users
 help / color / mirror / code / Atom feed
* can strftime show 'p.m.' instead of 'PM'?
@ 2012-04-28 18:55 TJ Luoma
  2012-04-28 21:10 ` Benjamin R. Haskell
  2012-04-28 21:20 ` Mark van Dijk
  0 siblings, 2 replies; 4+ messages in thread
From: TJ Luoma @ 2012-04-28 18:55 UTC (permalink / raw)
  To: zsh-users


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''.

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.

Thanks

TjL




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

* Re: can strftime show 'p.m.' instead of 'PM'?
  2012-04-28 18:55 can strftime show 'p.m.' instead of 'PM'? TJ Luoma
@ 2012-04-28 21:10 ` Benjamin R. Haskell
  2012-04-28 21:45   ` TJ Luoma
  2012-04-28 21:20 ` Mark van Dijk
  1 sibling, 1 reply; 4+ messages in thread
From: Benjamin R. Haskell @ 2012-04-28 21:10 UTC (permalink / raw)
  To: TJ Luoma; +Cc: zsh-users

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


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

* Re: can strftime show 'p.m.' instead of 'PM'?
  2012-04-28 18:55 can strftime show 'p.m.' instead of 'PM'? TJ Luoma
  2012-04-28 21:10 ` Benjamin R. Haskell
@ 2012-04-28 21:20 ` Mark van Dijk
  1 sibling, 0 replies; 4+ messages in thread
From: Mark van Dijk @ 2012-04-28 21:20 UTC (permalink / raw)
  To: zsh-users

On Sat, 28 Apr 2012 14:55:25 -0400
TJ Luoma <luomat@gmail.com> 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 :-)

One shall never debate the validity of taste. Unless it regards
the dreadful modern popular music. But in my experience the
exploration of zsh is all about, erm, "picayunicies". Pardon my spanish
por favor.

> 
> `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''.
> 
> 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.
> 
> Thanks
> 
> TjL

I'm not sure if my idea will help you because from the looks of it this
also uses strftime - but I'll share the idea anyway.

You can use ZSH's prompt expansion. In the zshmisc man (although i
always just 'man zshall') you can find 'Date and time' for prompt
expansion. Further, zshexpn explains that you can expand these in brace
expansions á là:

% foo='%D{%F %r}'   -- this part comes from zshmisc
% print ${(%)foo}   -- this part comes from zshexpn
2012-04-28 10:59:15 PM

So if you expand further (there are probably better methods?):

% print ${${${(%)foo}/AM/a.m}/PM/p.m.}
2012-04-28 10:59:57 p.m.


One thing by the way that seems to not work quite correctly from the
looks of it:

literally print the prompt string:
% echo $(echo '%D{%F %r}')     
%D{%F %r}  -- expected, works

immediately formulate the time out of it:
% echo ${(%)$(echo '%D{%F %r}')} 
2012-04-28 }  -- not expected

Oh well, who can blame zsh for not keeping up with this funky stuff. :)

HTH
- Mark


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

* Re: can strftime show 'p.m.' instead of 'PM'?
  2012-04-28 21:10 ` Benjamin R. Haskell
@ 2012-04-28 21:45   ` TJ Luoma
  0 siblings, 0 replies; 4+ messages in thread
From: TJ Luoma @ 2012-04-28 21:45 UTC (permalink / raw)
  To: zsh-users



On Saturday, April 28, 2012 at 5:10 PM, Benjamin R. Haskell wrote:

> 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.)


Ah! That explains why it seems to work sometimes but not others. I must have seen it differently on my Linux account on my web host.
 
> 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.}
Terrific! Thanks.
 
I'm not so much worried about efficiency as I like to know what my alternatives are. I'm going to alias this anyway, so I might as well use the 'efficient' version.

(more below)

On Saturday, April 28, 2012 at 5:20 PM, Mark van Dijk wrote:

> One shall never debate the validity of taste. Unless it regards
> the dreadful modern popular music. 

These kids these days with their rock & roll music! :-)

 
> But in my experience the
> exploration of zsh is all about, erm, "picayunicies". 


If I ever create my own Linux distribution customized to my own preferences, I'm going to call it "picayunicies" :-)

TjL

ps - thanks!



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

end of thread, other threads:[~2012-04-28 21:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-28 18:55 can strftime show 'p.m.' instead of 'PM'? TJ Luoma
2012-04-28 21:10 ` Benjamin R. Haskell
2012-04-28 21:45   ` TJ Luoma
2012-04-28 21:20 ` Mark van Dijk

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).