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

* lib/time.rb (Time.rfc2822, Time#rfc2822): preserve localtimeness.

* lib/pp.rb: pretty_print_cycled is renamed to pretty_print_cycle.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2742 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2002-08-24 05:18:08 +00:00
parent 4b0f91401c
commit 9c4a482229
3 changed files with 47 additions and 12 deletions

View file

@ -1,3 +1,9 @@
Sat Aug 24 13:57:28 2002 Tanaka Akira <akr@m17n.org>
* lib/time.rb (Time.rfc2822, Time#rfc2822): preserve localtimeness.
* lib/pp.rb: pretty_print_cycled is renamed to pretty_print_cycle.
Fri Aug 23 23:59:57 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net> Fri Aug 23 23:59:57 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net>
* eval.c (method_call): check receiver is defined. * eval.c (method_call): check receiver is defined.

View file

@ -83,9 +83,9 @@ PP#pp to print the object.
== methods == methods
--- pp(obj) --- pp(obj)
adds ((|obj|)) to the pretty printing buffer adds ((|obj|)) to the pretty printing buffer
using Object#pretty_print or Object#pretty_print_cycled. using Object#pretty_print or Object#pretty_print_cycle.
Object#pretty_print_cycled is used when ((|obj|)) is already Object#pretty_print_cycle is used when ((|obj|)) is already
printed, a.k.a the object reference chain has a cycle. printed, a.k.a the object reference chain has a cycle.
--- object_group(obj) { ... } --- object_group(obj) { ... }
@ -111,7 +111,7 @@ PP#pp to print the object.
This module provides predefined pretty_print() methods for some of This module provides predefined pretty_print() methods for some of
the most commonly used built-in classes for convenience. the most commonly used built-in classes for convenience.
--- pretty_print_cycled(pp) --- pretty_print_cycle(pp)
is a default pretty printing method for general objects that are is a default pretty printing method for general objects that are
detected as part of a cycle. detected as part of a cycle.
@ -179,7 +179,7 @@ class PP < PrettyPrint
id = obj.__id__ id = obj.__id__
if Thread.current[InspectKey].include? id if Thread.current[InspectKey].include? id
group {obj.pretty_print_cycled self} group {obj.pretty_print_cycle self}
return return
end end
@ -273,7 +273,7 @@ class PP < PrettyPrint
end end
end end
def pretty_print_cycled(pp) def pretty_print_cycle(pp)
pp.object_address_group(self) { pp.object_address_group(self) {
pp.breakable pp.breakable
pp.text '...' pp.text '...'
@ -304,7 +304,7 @@ class Array
} }
end end
def pretty_print_cycled(pp) def pretty_print_cycle(pp)
pp.text(empty? ? '[]' : '[...]') pp.text(empty? ? '[]' : '[...]')
end end
end end
@ -314,7 +314,7 @@ class Hash
pp.pp_hash self pp.pp_hash self
end end
def pretty_print_cycled(pp) def pretty_print_cycle(pp)
pp.text(empty? ? '{}' : '{...}') pp.text(empty? ? '{}' : '{...}')
end end
end end
@ -341,7 +341,7 @@ class Struct
} }
end end
def pretty_print_cycled(pp) def pretty_print_cycle(pp)
pp.text sprintf("#<%s:...>", self.class.name) pp.text sprintf("#<%s:...>", self.class.name)
end end
end end
@ -440,7 +440,7 @@ end
[Numeric, Symbol, FalseClass, TrueClass, NilClass, Module].each {|c| [Numeric, Symbol, FalseClass, TrueClass, NilClass, Module].each {|c|
c.class_eval { c.class_eval {
alias :pretty_print_cycled :pretty_print alias :pretty_print_cycle :pretty_print
} }
} }

View file

@ -212,7 +212,10 @@ class Time
year year
end end
Time.utc(year, mon, day, hour, min, sec) - zone_offset(zone) t = Time.utc(year, mon, day, hour, min, sec)
offset = zone_offset(zone)
t = (t - offset).localtime if offset != 0 || zone == '+0000'
t
else else
raise ArgumentError.new("not RFC 2822 compliant date: #{date.inspect}") raise ArgumentError.new("not RFC 2822 compliant date: #{date.inspect}")
end end
@ -303,7 +306,7 @@ class Time
where zone is [+-]hhmm. where zone is [+-]hhmm.
If self is a UTC time, +0000 is used as zone. If self is a UTC time, -0000 is used as zone.
=end =end
RFC2822_DAY_NAME = [ RFC2822_DAY_NAME = [
@ -319,7 +322,7 @@ class Time
day, RFC2822_MONTH_NAME[mon-1], year, day, RFC2822_MONTH_NAME[mon-1], year,
hour, min, sec) + hour, min, sec) +
if utc? if utc?
'+0000' '-0000'
else else
off = utc_offset off = utc_offset
sign = off < 0 ? '-' : '+' sign = off < 0 ? '-' : '+'
@ -447,6 +450,32 @@ if __FILE__ == $0
Time.httpdate("Fri, 31 Dec 1999 23:59:59 GMT")) Time.httpdate("Fri, 31 Dec 1999 23:59:59 GMT"))
end end
def test_rfc3339
t = Time.utc(1985, 4, 12, 23, 20, 50, 520000)
s = "1985-04-12T23:20:50.52Z"
assert_equal(t, Time.iso8601(s))
assert_equal(s, t.iso8601(2))
t = Time.utc(1996, 12, 20, 0, 39, 57)
s = "1996-12-19T16:39:57-08:00"
assert_equal(t, Time.iso8601(s))
# There is no way to generate time string with arbitrary timezone.
s = "1996-12-20T00:39:57Z"
assert_equal(t, Time.iso8601(s))
assert_equal(s, t.iso8601)
t = Time.utc(1990, 12, 31, 23, 59, 60)
s = "1990-12-31T23:59:60Z"
assert_equal(t, Time.iso8601(s))
# leap second is representable only if timezone file has it.
s = "1990-12-31T15:59:60-08:00"
assert_equal(t, Time.iso8601(s))
t = Time.utc(1937, 1, 1, 11, 40, 27, 870000)
s = "1937-01-01T12:00:27.87+00:20"
assert_equal(t, Time.iso8601(s))
end
# http://www.w3.org/TR/xmlschema-2/ # http://www.w3.org/TR/xmlschema-2/
def test_xmlschema def test_xmlschema
assert_equal(Time.utc(1999, 5, 31, 13, 20, 0) + 5 * 3600, assert_equal(Time.utc(1999, 5, 31, 13, 20, 0) + 5 * 3600,