Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: zsh-3.1.2-zefram3: 12 hour clock (2)



pws@xxxxxxxxxxxxxxxxxxx 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@xxxxxx>       Tel: +39 50 911239
WWW:  http://www.ifh.de/~pws/
Gruppo Teorico, Dipartimento di Fisica
Piazza Torricelli 2, 56100 Pisa, Italy



Messages sorted by: Reverse Date, Date, Thread, Author