zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: zsh-3.1.2-zefram3: 12 hour clock in prompts
@ 1998-01-16 13:14 pws
  1998-01-16 14:27 ` Andrew Main
  1998-01-19  9:15 ` PATCH: zsh-3.1.2-zefram3: 12 hour clock (2) Peter Stephenson
  0 siblings, 2 replies; 5+ messages in thread
From: pws @ 1998-01-16 13:14 UTC (permalink / raw)
  To: Zsh hackers list

It looks (as I mentioned before) as if someone has rationalised the %l
strftime sequence to do the same as in strftime(), i.e. print a space
before a number less than 10 in an hour given in 12-hour format.
Since this makes me shriek with frustration every time I look at my
prompt, which is often, the best thing to do is probably the same as
with the 24-hour version %k, where there is an additional sequence %K
which suppresses the space.  Luckily %L is free, so this makes the 12
and 24 hour versions nicely consistent.  (Historically, both %k and %l
suppressed the space, so this is also the natural way to update it.)

*** Doc/Zsh/prompt.yo.%L	Fri Jan 16 14:26:01 1998
--- Doc/Zsh/prompt.yo	Fri Jan 16 14:26:23 1998
***************
*** 103,112 ****
  )
  item(tt(%D{)var(string)tt(}))(
  var(string) is formatted using the tt(strftime) function.
! See manref(strftime)(3) for more details.  Two additional codes are
  available:  tt(%f) prints the day of the month, like tt(%e) but
! without any preceding space if the day is a single digit, and tt(%K)
! corresponds to tt(%k) for the hour of the day in the same way.
  )
  item(tt(%l))(
  The line (tty) the user is logged in on.
--- 103,113 ----
  )
  item(tt(%D{)var(string)tt(}))(
  var(string) is formatted using the tt(strftime) function.
! See manref(strftime)(3) for more details.  Three additional codes are
  available:  tt(%f) prints the day of the month, like tt(%e) but
! without any preceding space if the day is a single digit, and
! tt(%K)/tt(%L) correspond to tt(%k)/tt(%l) for the hour of the day
! (24/12 hour clock) in the same way.
  )
  item(tt(%l))(
  The line (tty) the user is logged in on.
*** Src/utils.c.%L	Fri Jan 16 14:22:27 1998
--- Src/utils.c	Fri Jan 16 14:41:30 1998
***************
*** 1318,1326 ****
  #else
      char *origbuf = buf;
  #endif
-     static char *lstr[] =
-     {"12", " 1", " 2", " 3", " 4", " 5", " 6", " 7", " 8", " 9",
-      "10", "11"};
      char tmp[3];
  
  
--- 1318,1323 ----
***************
*** 1351,1357 ****
  		*buf++ = '0' + tm->tm_hour % 10;
  		break;
  	    case 'l':
! 		strucpy(&buf, lstr[tm->tm_hour % 12]);
  		break;
  	    case 'm':
  		*buf++ = '0' + (tm->tm_mon + 1) / 10;
--- 1348,1359 ----
  		*buf++ = '0' + tm->tm_hour % 10;
  		break;
  	    case 'l':
! 	    case 'L':
! 	        if ((tm->tm_hour % 12) > 10)
! 		  *buf++ = '1';
! 		else if (fmt[-1] == 'l')
! 		  *buf++ = ' ';
! 		*buf++ = '0' + ((tm->tm_hour % 12) % 10);
  		break;
  	    case 'm':
  		*buf++ = '0' + (tm->tm_mon + 1) / 10;

-- 
Peter Stephenson <pws@ibmth.difi.unipi.it>       Tel: +39 50 911239
WWW:  http://www.ifh.de/~pws/
Gruppo Teorico, Dipartimento di Fisica
Piazza Torricelli 2, 56100 Pisa, Italy


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

* Re: PATCH: zsh-3.1.2-zefram3: 12 hour clock in prompts
  1998-01-16 13:14 PATCH: zsh-3.1.2-zefram3: 12 hour clock in prompts pws
@ 1998-01-16 14:27 ` Andrew Main
  1998-01-16 14:48   ` Peter Stephenson
  1998-01-19  9:15 ` PATCH: zsh-3.1.2-zefram3: 12 hour clock (2) Peter Stephenson
  1 sibling, 1 reply; 5+ messages in thread
From: Andrew Main @ 1998-01-16 14:27 UTC (permalink / raw)
  To: pws; +Cc: zsh-workers

pws@ibmth.difi.unipi.it wrote:
>It looks (as I mentioned before) as if someone has rationalised the %l
>strftime sequence to do the same as in strftime(), i.e. print a space
>before a number less than 10 in an hour given in 12-hour format.

Hmm.

ztrftime() is disgusting.  I'd really like to strip it down to what POSIX
requires date(1) to handle (and make it really POSIX conformant) -- to
hell with existing users, it's used almost purely for prompts.  Then do
what should have been done with strftime() from the start: add flags to
the % sequences to specify the type of fill.  What do people think?

-zefram


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

* Re: PATCH: zsh-3.1.2-zefram3: 12 hour clock in prompts
  1998-01-16 14:27 ` Andrew Main
@ 1998-01-16 14:48   ` Peter Stephenson
  0 siblings, 0 replies; 5+ messages in thread
From: Peter Stephenson @ 1998-01-16 14:48 UTC (permalink / raw)
  To: Zsh hackers list

Andrew Main wrote:
> ztrftime() is disgusting.  I'd really like to strip it down to what POSIX
> requires date(1) to handle (and make it really POSIX conformant) -- to
> hell with existing users, it's used almost purely for prompts.  Then do
> what should have been done with strftime() from the start: add flags to
> the % sequences to specify the type of fill.  What do people think?

I don't think it's really long enough to worry about.  We can only
ended up re-implementing the whole of strftime(), which is even more
to worry about.  It would have been nice to have had fills handled properly,
but that's too late to do in any kind of compatible way.  Also, every
time something in zsh gets stripped down it's usually the bits I was
using that disappear (unless I'm doing it myself).  I use print -P
sometimes to format dates and times and it's inconvenient to find out
bits of the system's strftime() are not implemented (some date's don't
take +fmt).

-- 
Peter Stephenson <pws@ifh.de>       Tel: +39 50 911239
WWW:  http://www.ifh.de/~pws/
Gruppo Teorico, Dipartimento di Fisica
Piazza Torricelli 2, 56100 Pisa, Italy


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

* PATCH: zsh-3.1.2-zefram3: 12 hour clock (2)
  1998-01-16 13:14 PATCH: zsh-3.1.2-zefram3: 12 hour clock in prompts pws
  1998-01-16 14:27 ` Andrew Main
@ 1998-01-19  9:15 ` Peter Stephenson
  1998-01-19 11:23   ` PATCH: zsh-3.1.2-zefram3: 12 hour clock (3) Peter Stephenson
  1 sibling, 1 reply; 5+ messages in thread
From: Peter Stephenson @ 1998-01-19  9:15 UTC (permalink / raw)
  To: Zsh hackers list

pws@ibmth.difi.unipi.it wrote:
> It looks (as I mentioned before) as if someone has rationalised the %l
> strftime sequence to do the same as in strftime(), i.e. print a space
> before a number less than 10 in an hour given in 12-hour format.
> Since this makes me shriek with frustration every time I look at my
> prompt, which is often, the best thing to do is probably the same as
> with the 24-hour version %k, where there is an additional sequence %K
> which suppresses the space.  Luckily %L is free, so this makes the 12
> and 24 hour versions nicely consistent.  (Historically, both %k and %l
> suppressed the space, so this is also the natural way to update it.)

In case anybody else has been using this, there's a slight mistake
(10 is not greater than 10).  Here's the corrected version.

*** Doc/Zsh/prompt.yo.%L	Fri Jan 16 14:26:01 1998
--- Doc/Zsh/prompt.yo	Fri Jan 16 14:26:23 1998
***************
*** 103,112 ****
  )
  item(tt(%D{)var(string)tt(}))(
  var(string) is formatted using the tt(strftime) function.
! See manref(strftime)(3) for more details.  Two additional codes are
  available:  tt(%f) prints the day of the month, like tt(%e) but
! without any preceding space if the day is a single digit, and tt(%K)
! corresponds to tt(%k) for the hour of the day in the same way.
  )
  item(tt(%l))(
  The line (tty) the user is logged in on.
--- 103,113 ----
  )
  item(tt(%D{)var(string)tt(}))(
  var(string) is formatted using the tt(strftime) function.
! See manref(strftime)(3) for more details.  Three additional codes are
  available:  tt(%f) prints the day of the month, like tt(%e) but
! without any preceding space if the day is a single digit, and
! tt(%K)/tt(%L) correspond to tt(%k)/tt(%l) for the hour of the day
! (24/12 hour clock) in the same way.
  )
  item(tt(%l))(
  The line (tty) the user is logged in on.
*** Src/utils.c.%L	Fri Jan 16 14:22:27 1998
--- Src/utils.c	Mon Jan 19 10:06:55 1998
***************
*** 1318,1326 ****
  #else
      char *origbuf = buf;
  #endif
-     static char *lstr[] =
-     {"12", " 1", " 2", " 3", " 4", " 5", " 6", " 7", " 8", " 9",
-      "10", "11"};
      char tmp[3];
  
  
--- 1318,1323 ----
***************
*** 1351,1357 ****
  		*buf++ = '0' + tm->tm_hour % 10;
  		break;
  	    case 'l':
! 		strucpy(&buf, lstr[tm->tm_hour % 12]);
  		break;
  	    case 'm':
  		*buf++ = '0' + (tm->tm_mon + 1) / 10;
--- 1348,1359 ----
  		*buf++ = '0' + tm->tm_hour % 10;
  		break;
  	    case 'l':
! 	    case 'L':
! 	        if ((tm->tm_hour % 12) > 9)
! 		  *buf++ = '1';
! 		else if (fmt[-1] == 'l')
! 		  *buf++ = ' ';
! 		*buf++ = '0' + ((tm->tm_hour % 12) % 10);
  		break;
  	    case 'm':
  		*buf++ = '0' + (tm->tm_mon + 1) / 10;

-- 
Peter Stephenson <pws@ifh.de>       Tel: +39 50 911239
WWW:  http://www.ifh.de/~pws/
Gruppo Teorico, Dipartimento di Fisica
Piazza Torricelli 2, 56100 Pisa, Italy


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

* PATCH: zsh-3.1.2-zefram3: 12 hour clock (3)
  1998-01-19  9:15 ` PATCH: zsh-3.1.2-zefram3: 12 hour clock (2) Peter Stephenson
@ 1998-01-19 11:23   ` Peter Stephenson
  0 siblings, 0 replies; 5+ messages in thread
From: Peter Stephenson @ 1998-01-19 11:23 UTC (permalink / raw)
  To: Zsh hackers list

GAH!  I'll get this right eventually.  The only problem is not being
able to count.

*** Doc/Zsh/prompt.yo.%L	Fri Jan 16 14:26:01 1998
--- Doc/Zsh/prompt.yo	Fri Jan 16 14:26:23 1998
***************
*** 103,112 ****
  )
  item(tt(%D{)var(string)tt(}))(
  var(string) is formatted using the tt(strftime) function.
! See manref(strftime)(3) for more details.  Two additional codes are
  available:  tt(%f) prints the day of the month, like tt(%e) but
! without any preceding space if the day is a single digit, and tt(%K)
! corresponds to tt(%k) for the hour of the day in the same way.
  )
  item(tt(%l))(
  The line (tty) the user is logged in on.
--- 103,113 ----
  )
  item(tt(%D{)var(string)tt(}))(
  var(string) is formatted using the tt(strftime) function.
! See manref(strftime)(3) for more details.  Three additional codes are
  available:  tt(%f) prints the day of the month, like tt(%e) but
! without any preceding space if the day is a single digit, and
! tt(%K)/tt(%L) correspond to tt(%k)/tt(%l) for the hour of the day
! (24/12 hour clock) in the same way.
  )
  item(tt(%l))(
  The line (tty) the user is logged in on.
*** Src/utils.c.%L	Fri Jan 16 14:22:27 1998
--- Src/utils.c	Mon Jan 19 12:06:59 1998
***************
*** 1309,1314 ****
--- 1309,1315 ----
  int
  ztrftime(char *buf, int bufsize, char *fmt, struct tm *tm)
  {
+     int hr12;
  #ifndef HAVE_STRFTIME
      static char *astr[] =
      {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
***************
*** 1318,1326 ****
  #else
      char *origbuf = buf;
  #endif
-     static char *lstr[] =
-     {"12", " 1", " 2", " 3", " 4", " 5", " 6", " 7", " 8", " 9",
-      "10", "11"};
      char tmp[3];
  
  
--- 1319,1324 ----
***************
*** 1351,1357 ****
  		*buf++ = '0' + tm->tm_hour % 10;
  		break;
  	    case 'l':
! 		strucpy(&buf, lstr[tm->tm_hour % 12]);
  		break;
  	    case 'm':
  		*buf++ = '0' + (tm->tm_mon + 1) / 10;
--- 1349,1363 ----
  		*buf++ = '0' + tm->tm_hour % 10;
  		break;
  	    case 'l':
! 	    case 'L':
! 		hr12 = tm->tm_hour % 12;
! 		if (hr12 == 0)
! 		    hr12 = 12;
! 	        if (hr12 > 9)
! 		  *buf++ = '1';
! 		else if (fmt[-1] == 'l')
! 		  *buf++ = ' ';
! 		*buf++ = '0' + (hr12 % 10);
  		break;
  	    case 'm':
  		*buf++ = '0' + (tm->tm_mon + 1) / 10;


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

end of thread, other threads:[~1998-01-19 11:44 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-01-16 13:14 PATCH: zsh-3.1.2-zefram3: 12 hour clock in prompts pws
1998-01-16 14:27 ` Andrew Main
1998-01-16 14:48   ` Peter Stephenson
1998-01-19  9:15 ` PATCH: zsh-3.1.2-zefram3: 12 hour clock (2) Peter Stephenson
1998-01-19 11:23   ` PATCH: zsh-3.1.2-zefram3: 12 hour clock (3) Peter Stephenson

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