зеркало из https://github.com/github/ruby.git
* 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:
Родитель
db1564ec1d
Коммит
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>
|
||||
|
||||
* 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.
|
||||
#
|
||||
def rfc2822
|
||||
sprintf('%s, %02d %s %04d %02d:%02d:%02d ',
|
||||
sprintf('%s, %02d %s %0*d %02d:%02d:%02d ',
|
||||
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) +
|
||||
if utc?
|
||||
'-0000'
|
||||
|
@ -464,9 +464,9 @@ class Time
|
|||
#
|
||||
def httpdate
|
||||
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],
|
||||
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)
|
||||
end
|
||||
|
||||
|
@ -485,8 +485,8 @@ class Time
|
|||
# Its default value is 0.
|
||||
#
|
||||
def xmlschema(fraction_digits=0)
|
||||
sprintf('%04d-%02d-%02dT%02d:%02d:%02d',
|
||||
year, mon, day, hour, min, sec) +
|
||||
sprintf('%0*d-%02d-%02dT%02d:%02d:%02d',
|
||||
year < 0 ? 5 : 4, year, mon, day, hour, min, sec) +
|
||||
if fraction_digits == 0
|
||||
''
|
||||
else
|
||||
|
|
|
@ -496,7 +496,13 @@ rb_strftime(char *s, size_t maxsize, const char *format, const struct vtm *vtm,
|
|||
continue;
|
||||
|
||||
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;
|
||||
|
||||
#ifdef MAILHEADER_EXT
|
||||
|
|
|
@ -188,6 +188,15 @@ class TestTimeExtension < Test::Unit::TestCase # :nodoc:
|
|||
end
|
||||
|
||||
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
|
||||
|
||||
def test_completion
|
||||
|
|
Загрузка…
Ссылка в новой задаче