From 70cac415298381ec7a3f978f729a0e0b97aec972 Mon Sep 17 00:00:00 2001
From: Kevin B Kenny <kennykb@acm.org>
Date: Wed, 8 Sep 2004 18:32:02 +0000
Subject: * compat/strftime.c (_conv): Corrected a problem where hour 0 would
 format as a blank format group with %k. * tests/clock.test (clock-41.1):
 Added regression test case for %k at the zero hour.

---
 ChangeLog         |  7 +++++++
 compat/strftime.c | 14 ++++++++++----
 tests/clock.test  |  6 +++++-
 3 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index c10802c..f615885 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2004-09-08  Kevin B. Kenny  <kennykb@acm.org>
+
+	* compat/strftime.c (_conv): Corrected a problem where hour 0
+	would format as a blank format group with %k.
+	* tests/clock.test (clock-41.1): Added regression test case for
+	%k at the zero hour.
+
 2004-09-07  Kevin B. Kenny  <kennykb@acm.org>
 
 	* generic/tclTimer.c: Removed a premature optimisation that
diff --git a/compat/strftime.c b/compat/strftime.c
index dbd7d54..609c193 100644
--- a/compat/strftime.c
+++ b/compat/strftime.c
@@ -10,7 +10,7 @@
  *
  * Changes 2002 Copyright (c) 2002 ActiveState Corporation.
  *
- * RCS: @(#) $Id: strftime.c,v 1.10.2.1 2004/05/18 21:52:56 kennykb Exp $
+ * RCS: @(#) $Id: strftime.c,v 1.10.2.2 2004/09/08 18:32:20 kennykb Exp $
  */
 
 /*
@@ -47,7 +47,7 @@
  */
 
 #if defined(LIBC_SCCS)
-static char *rcsid = "$Id: strftime.c,v 1.10.2.1 2004/05/18 21:52:56 kennykb Exp $";
+static char *rcsid = "$Id: strftime.c,v 1.10.2.2 2004/09/08 18:32:20 kennykb Exp $";
 #endif /* LIBC_SCCS */
 
 #include <time.h>
@@ -432,8 +432,14 @@ _conv(n, digits, pad)
     static char buf[10];
     register char *p;
 
-    for (p = buf + sizeof(buf) - 2; n > 0 && p > buf; n /= 10, --digits)
-	*p-- = (char)(n % 10 + '0');
+    p = buf + sizeof( buf ) - 1;
+    *p-- = '\0';
+    if ( n == 0 ) {
+	*p-- = '0'; --digits;
+    } else {
+	for (; n > 0 && p > buf; n /= 10, --digits)
+	    *p-- = (char)(n % 10 + '0');
+    }
     while (p > buf && digits-- > 0)
 	*p-- = (char) pad;
     return(_add(++p));
diff --git a/tests/clock.test b/tests/clock.test
index 2599dd7..6599218 100644
--- a/tests/clock.test
+++ b/tests/clock.test
@@ -10,7 +10,7 @@
 # See the file "license.terms" for information on usage and redistribution
 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 #
-# RCS: @(#) $Id: clock.test,v 1.22.2.5 2004/05/27 18:43:19 kennykb Exp $
+# RCS: @(#) $Id: clock.test,v 1.22.2.6 2004/09/08 18:32:20 kennykb Exp $
 
 set env(LC_TIME) POSIX
 
@@ -643,6 +643,10 @@ test clock-10.49 {ISO week-based calendar 2010-W02-1} {percentG} {
     clock format 1263168000 -format {%a %A %g %G %u %V %w} -gmt true; # 2010-1-11
 } {Mon Monday 10 2010 1 02 1}
 
+test clock-41.1 {regression test - format group %k when hour is 0 } {
+    clock format 0 -format %k -gmt true
+} { 0}
+
 # cleanup
 ::tcltest::cleanupTests
 return
-- 
cgit v0.12