summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-08-28 15:54:44 +0000
committershugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-08-28 15:54:44 +0000
commit77d7a80f9778d415165fff1c7ce0bf99b96b9ef3 (patch)
tree40678a446786335bcdc9df96f99b7f1406254671
parent9f3170663638393b60e39828b1b39e06201e8a7b (diff)
* strftime.c (rb_strftime): fixed a bug of padding.
* test/ruby/test_time.rb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18907 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog6
-rw-r--r--strftime.c2
-rw-r--r--test/ruby/test_time.rb33
3 files changed, 40 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 500cd93355..04a658ffc1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Fri Aug 29 00:53:40 2008 Shugo Maeda <shugo@ruby-lang.org>
+
+ * strftime.c (rb_strftime): fixed a bug of padding.
+
+ * test/ruby/test_time.rb: ditto.
+
Fri Aug 29 00:19:54 2008 NAKAMURA Usaku <usa@ruby-lang.org>
* win32/win32.c (set_pioinfo_extra): use MSVCRT's open() and close().
diff --git a/strftime.c b/strftime.c
index 2b8033cf28..fa0e6e6a69 100644
--- a/strftime.c
+++ b/strftime.c
@@ -277,7 +277,7 @@ rb_strftime(char *s, size_t maxsize, const char *format, const struct tm *timept
if (precision <= 0) precision = (def_prec); \
if (flags & BIT_OF(LEFT)) precision = 1; \
l = snprintf(s, endp - s, \
- ((!padding || padding == (def_pad)) ? "%.*"fmt : "%*"fmt), \
+ ((padding == '0' || (!padding && def_pad == '0')) ? "%.*"fmt : "%*"fmt), \
precision, val); \
if (l < 0) goto err; \
s += l; \
diff --git a/test/ruby/test_time.rb b/test/ruby/test_time.rb
index 237721c4db..a2c2b1b140 100644
--- a/test/ruby/test_time.rb
+++ b/test/ruby/test_time.rb
@@ -401,5 +401,38 @@ class TestTime < Test::Unit::TestCase
t = Time.mktime(2001, 10, 1)
assert_equal("2001-10-01", t.strftime("%F"))
+
+ t = Time.mktime(2001, 10, 1, 2, 0, 0)
+ assert_equal("01", t.strftime("%d"))
+ assert_equal("01", t.strftime("%0d"))
+ assert_equal(" 1", t.strftime("%_d"))
+ assert_equal(" 1", t.strftime("%e"))
+ assert_equal("01", t.strftime("%0e"))
+ assert_equal(" 1", t.strftime("%_e"))
+ assert_equal("02", t.strftime("%H"))
+ assert_equal("02", t.strftime("%0H"))
+ assert_equal(" 2", t.strftime("%_H"))
+ assert_equal("02", t.strftime("%I"))
+ assert_equal("02", t.strftime("%0I"))
+ assert_equal(" 2", t.strftime("%_I"))
+ assert_equal(" 2", t.strftime("%k"))
+ assert_equal("02", t.strftime("%0k"))
+ assert_equal(" 2", t.strftime("%_k"))
+ assert_equal(" 2", t.strftime("%l"))
+ assert_equal("02", t.strftime("%0l"))
+ assert_equal(" 2", t.strftime("%_l"))
+ t = Time.mktime(2001, 10, 1, 14, 0, 0)
+ assert_equal("14", t.strftime("%H"))
+ assert_equal("14", t.strftime("%0H"))
+ assert_equal("14", t.strftime("%_H"))
+ assert_equal("02", t.strftime("%I"))
+ assert_equal("02", t.strftime("%0I"))
+ assert_equal(" 2", t.strftime("%_I"))
+ assert_equal("14", t.strftime("%k"))
+ assert_equal("14", t.strftime("%0k"))
+ assert_equal("14", t.strftime("%_k"))
+ assert_equal(" 2", t.strftime("%l"))
+ assert_equal("02", t.strftime("%0l"))
+ assert_equal(" 2", t.strftime("%_l"))
end
end