* strftime.c: %Y format a year with 4 digits at least.
* lib/time.rb: format a year with 4 digits at least. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25906 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
db1564ec1d
commit
54370de9f4
@ -1,3 +1,9 @@
|
|||||||
|
Tue Nov 24 20:11:37 2009 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
|
* strftime.c: %Y format a year with 4 digits at least.
|
||||||
|
|
||||||
|
* lib/time.rb: format a year with 4 digits at least.
|
||||||
|
|
||||||
Tue Nov 24 20:05:27 2009 Tanaka Akira <akr@fsij.org>
|
Tue Nov 24 20:05:27 2009 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
* defs/known_errors.def: more errors.
|
* defs/known_errors.def: more errors.
|
||||||
|
12
lib/time.rb
12
lib/time.rb
@ -432,9 +432,9 @@ class Time
|
|||||||
# If +self+ is a UTC time, -0000 is used as zone.
|
# If +self+ is a UTC time, -0000 is used as zone.
|
||||||
#
|
#
|
||||||
def rfc2822
|
def rfc2822
|
||||||
sprintf('%s, %02d %s %04d %02d:%02d:%02d ',
|
sprintf('%s, %02d %s %0*d %02d:%02d:%02d ',
|
||||||
RFC2822_DAY_NAME[wday],
|
RFC2822_DAY_NAME[wday],
|
||||||
day, RFC2822_MONTH_NAME[mon-1], year,
|
day, RFC2822_MONTH_NAME[mon-1], year < 0 ? 5 : 4, year,
|
||||||
hour, min, sec) +
|
hour, min, sec) +
|
||||||
if utc?
|
if utc?
|
||||||
'-0000'
|
'-0000'
|
||||||
@ -464,9 +464,9 @@ class Time
|
|||||||
#
|
#
|
||||||
def httpdate
|
def httpdate
|
||||||
t = dup.utc
|
t = dup.utc
|
||||||
sprintf('%s, %02d %s %04d %02d:%02d:%02d GMT',
|
sprintf('%s, %02d %s %0*d %02d:%02d:%02d GMT',
|
||||||
RFC2822_DAY_NAME[t.wday],
|
RFC2822_DAY_NAME[t.wday],
|
||||||
t.day, RFC2822_MONTH_NAME[t.mon-1], t.year,
|
t.day, RFC2822_MONTH_NAME[t.mon-1], t.year < 0 ? 5 : 4, t.year,
|
||||||
t.hour, t.min, t.sec)
|
t.hour, t.min, t.sec)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -485,8 +485,8 @@ class Time
|
|||||||
# Its default value is 0.
|
# Its default value is 0.
|
||||||
#
|
#
|
||||||
def xmlschema(fraction_digits=0)
|
def xmlschema(fraction_digits=0)
|
||||||
sprintf('%04d-%02d-%02dT%02d:%02d:%02d',
|
sprintf('%0*d-%02d-%02dT%02d:%02d:%02d',
|
||||||
year, mon, day, hour, min, sec) +
|
year < 0 ? 5 : 4, year, mon, day, hour, min, sec) +
|
||||||
if fraction_digits == 0
|
if fraction_digits == 0
|
||||||
''
|
''
|
||||||
else
|
else
|
||||||
|
@ -496,7 +496,13 @@ rb_strftime(char *s, size_t maxsize, const char *format, const struct vtm *vtm,
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
case 'Y': /* year with century */
|
case 'Y': /* year with century */
|
||||||
FMTV('0', 1, "d", vtm->year);
|
if (FIXNUM_P(vtm->year)) {
|
||||||
|
long y = FIX2LONG(vtm->year);
|
||||||
|
FMT('0', 0 <= y ? 4 : 5, "ld", y);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
FMTV('0', 4, "d", vtm->year);
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
#ifdef MAILHEADER_EXT
|
#ifdef MAILHEADER_EXT
|
||||||
|
@ -188,6 +188,15 @@ class TestTimeExtension < Test::Unit::TestCase # :nodoc:
|
|||||||
end
|
end
|
||||||
|
|
||||||
assert_equal(249, Time.xmlschema("2008-06-05T23:49:23.000249+09:00").usec)
|
assert_equal(249, Time.xmlschema("2008-06-05T23:49:23.000249+09:00").usec)
|
||||||
|
|
||||||
|
assert_equal("10000-01-01T00:00:00Z", Time.utc(10000).xmlschema)
|
||||||
|
assert_equal("9999-01-01T00:00:00Z", Time.utc(9999).xmlschema)
|
||||||
|
assert_equal("0001-01-01T00:00:00Z", Time.utc(1).xmlschema) # 1 AD
|
||||||
|
assert_equal("0000-01-01T00:00:00Z", Time.utc(0).xmlschema) # 1 BC
|
||||||
|
assert_equal("-0001-01-01T00:00:00Z", Time.utc(-1).xmlschema) # 2 BC
|
||||||
|
assert_equal("-0004-01-01T00:00:00Z", Time.utc(-4).xmlschema) # 5 BC
|
||||||
|
assert_equal("-9999-01-01T00:00:00Z", Time.utc(-9999).xmlschema)
|
||||||
|
assert_equal("-10000-01-01T00:00:00Z", Time.utc(-10000).xmlschema)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_completion
|
def test_completion
|
||||||
|
Loading…
x
Reference in New Issue
Block a user