1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* strftime.c (rb_strftime): A width specifier for %t and %n should

work.  [ruby-dev:37160]
* test/ruby/test_time.rb (test_strftime): ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@20340 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
shugo 2008-11-24 14:01:47 +00:00
parent aa498028b2
commit bf1d53e2e0
3 changed files with 32 additions and 10 deletions

View file

@ -1,3 +1,10 @@
Mon Nov 24 22:57:25 2008 Shugo Maeda <shugo@ruby-lang.org>
* strftime.c (rb_strftime): A width specifier for %t and %n should
work. [ruby-dev:37160]
* test/ruby/test_time.rb (test_strftime): ditto.
Mon Nov 24 22:07:07 2008 Shugo Maeda <shugo@ruby-lang.org>
* strftime.c (rb_strftime): The precision of %0N should be 9.

View file

@ -270,6 +270,16 @@ rb_strftime(char *s, size_t maxsize, const char *format, const struct tm *timept
goto unknown; \
} while (0)
#define NEEDS(n) do if (s + (n) >= endp - 1) goto err; while (0)
#define FILL_PADDING(i) do { \
if (!(flags & BIT_OF(LEFT)) && precision > i) { \
NEEDS(precision); \
memset(s, padding ? padding : ' ', precision - i); \
s += precision - i; \
} \
else { \
NEEDS(i); \
} \
} while (0);
#define FMT(def_pad, def_prec, fmt, val) \
do { \
int l; \
@ -540,12 +550,12 @@ rb_strftime(char *s, size_t maxsize, const char *format, const struct tm *timept
#ifdef SYSV_EXT
case 'n': /* same as \n */
NEEDS(1);
FILL_PADDING(1);
*s++ = '\n';
continue;
case 't': /* same as \t */
NEEDS(1);
FILL_PADDING(1);
*s++ = '\t';
continue;
@ -741,14 +751,7 @@ rb_strftime(char *s, size_t maxsize, const char *format, const struct tm *timept
break;
}
if (i) {
if (!(flags & BIT_OF(LEFT)) && precision > i) {
NEEDS(precision);
memset(s, padding ? padding : ' ', precision - i);
s += precision - i;
}
else {
NEEDS(i);
}
FILL_PADDING(i);
memcpy(s, tp, i);
switch (flags & (BIT_OF(UPPER)|BIT_OF(LOWER))) {
case BIT_OF(UPPER):

View file

@ -449,5 +449,17 @@ class TestTime < Test::Unit::TestCase
t = Time.mktime(1970, 1, 18)
assert_equal("0", t.strftime("%w"))
assert_equal("7", t.strftime("%u"))
# [ruby-dev:37160]
assert_equal("\t", T2000.strftime("%t"))
assert_equal("\t", T2000.strftime("%0t"))
assert_equal("\t", T2000.strftime("%1t"))
assert_equal(" \t", T2000.strftime("%3t"))
assert_equal("00\t", T2000.strftime("%03t"))
assert_equal("\n", T2000.strftime("%n"))
assert_equal("\n", T2000.strftime("%0n"))
assert_equal("\n", T2000.strftime("%1n"))
assert_equal(" \n", T2000.strftime("%3n"))
assert_equal("00\n", T2000.strftime("%03n"))
end
end