mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/time.rb (Time#rfc2822): pad leading zeros for year.
(Time#httpdate): ditto. (Time#xmlschema): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23251 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
6df2f3d59c
commit
d9dd33fc27
3 changed files with 22 additions and 3 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
Wed Apr 22 03:06:56 2009 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
|
* lib/time.rb (Time#rfc2822): pad leading zeros for year.
|
||||||
|
(Time#httpdate): ditto.
|
||||||
|
(Time#xmlschema): ditto.
|
||||||
|
|
||||||
Wed Apr 22 02:10:48 2009 Tanaka Akira <akr@fsij.org>
|
Wed Apr 22 02:10:48 2009 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
* lib/time.rb (Time#xmlschema): use subsec instead of nsec.
|
* lib/time.rb (Time#xmlschema): use subsec instead of nsec.
|
||||||
|
|
|
@ -445,7 +445,7 @@ 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 %d %02d:%02d:%02d ',
|
sprintf('%s, %02d %s %04d %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,
|
||||||
hour, min, sec) +
|
hour, min, sec) +
|
||||||
|
@ -477,7 +477,7 @@ class Time
|
||||||
#
|
#
|
||||||
def httpdate
|
def httpdate
|
||||||
t = dup.utc
|
t = dup.utc
|
||||||
sprintf('%s, %02d %s %d %02d:%02d:%02d GMT',
|
sprintf('%s, %02d %s %04d %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,
|
||||||
t.hour, t.min, t.sec)
|
t.hour, t.min, t.sec)
|
||||||
|
@ -498,7 +498,7 @@ class Time
|
||||||
# Its default value is 0.
|
# Its default value is 0.
|
||||||
#
|
#
|
||||||
def xmlschema(fraction_digits=0)
|
def xmlschema(fraction_digits=0)
|
||||||
sprintf('%d-%02d-%02dT%02d:%02d:%02d',
|
sprintf('%04d-%02d-%02dT%02d:%02d:%02d',
|
||||||
year, mon, day, hour, min, sec) +
|
year, mon, day, hour, min, sec) +
|
||||||
if fraction_digits == 0
|
if fraction_digits == 0
|
||||||
''
|
''
|
||||||
|
|
|
@ -45,6 +45,11 @@ class TestTimeExtention < Test::Unit::TestCase # :nodoc:
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_encode_rfc2822
|
||||||
|
t = Time.utc(1)
|
||||||
|
assert_equal("Mon, 01 Jan 0001 00:00:00 -0000", t.rfc2822)
|
||||||
|
end
|
||||||
|
|
||||||
def test_rfc2616
|
def test_rfc2616
|
||||||
t = Time.utc(1994, 11, 6, 8, 49, 37)
|
t = Time.utc(1994, 11, 6, 8, 49, 37)
|
||||||
assert_equal(t, Time.httpdate("Sun, 06 Nov 1994 08:49:37 GMT"))
|
assert_equal(t, Time.httpdate("Sun, 06 Nov 1994 08:49:37 GMT"))
|
||||||
|
@ -69,6 +74,11 @@ class TestTimeExtention < Test::Unit::TestCase # :nodoc:
|
||||||
Time.httpdate('Sunday, 23-Dec-07 11:22:33 GMT'))
|
Time.httpdate('Sunday, 23-Dec-07 11:22:33 GMT'))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_encode_httpdate
|
||||||
|
t = Time.utc(1)
|
||||||
|
assert_equal("Mon, 01 Jan 0001 00:00:00 GMT", t.httpdate)
|
||||||
|
end
|
||||||
|
|
||||||
def test_rfc3339
|
def test_rfc3339
|
||||||
t = Time.utc(1985, 4, 12, 23, 20, 50, 520000)
|
t = Time.utc(1985, 4, 12, 23, 20, 50, 520000)
|
||||||
s = "1985-04-12T23:20:50.52Z"
|
s = "1985-04-12T23:20:50.52Z"
|
||||||
|
@ -165,6 +175,9 @@ class TestTimeExtention < Test::Unit::TestCase # :nodoc:
|
||||||
assert_equal("1970-01-01T09:00:00.0123456789012345678+09:00", t.xmlschema(19))
|
assert_equal("1970-01-01T09:00:00.0123456789012345678+09:00", t.xmlschema(19))
|
||||||
assert_equal("1970-01-01T09:00:00.01234567890123456789+09:00", t.xmlschema(20))
|
assert_equal("1970-01-01T09:00:00.01234567890123456789+09:00", t.xmlschema(20))
|
||||||
|
|
||||||
|
t = Time.utc(1)
|
||||||
|
assert_equal("0001-01-01T00:00:00Z", t.xmlschema)
|
||||||
|
|
||||||
begin
|
begin
|
||||||
Time.at(-1)
|
Time.at(-1)
|
||||||
rescue ArgumentError
|
rescue ArgumentError
|
||||||
|
|
Loading…
Reference in a new issue