* lib/date/format.rb (_xmlschema): some improvements.
* lib/date/format.rb (_parse): a new hint compfunc. [experimental] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14721 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
b3e3c8a578
commit
343a414ab0
@ -1,3 +1,9 @@
|
|||||||
|
Wed Dec 26 21:27:02 2007 Tadayoshi Funaba <tadf@dotrb.org>
|
||||||
|
|
||||||
|
* lib/date/format.rb (_xmlschema): some improvements.
|
||||||
|
|
||||||
|
* lib/date/format.rb (_parse): a new hint compfunc. [experimental]
|
||||||
|
|
||||||
Wed Dec 26 17:31:08 2007 Tanaka Akira <akr@fsij.org>
|
Wed Dec 26 17:31:08 2007 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
* io.c (io_fflush): check closed fptr after rb_write_internal to avoid
|
* io.c (io_fflush): check closed fptr after rb_write_internal to avoid
|
||||||
|
@ -1101,6 +1101,8 @@ class Date
|
|||||||
case k
|
case k
|
||||||
when :comp, :complete
|
when :comp, :complete
|
||||||
e._comp = v
|
e._comp = v
|
||||||
|
when :compfunc
|
||||||
|
e._compfunc = v
|
||||||
when :style, :endian, :endianness, :order
|
when :style, :endian, :endianness, :order
|
||||||
v = {
|
v = {
|
||||||
:jp => :jp,
|
:jp => :jp,
|
||||||
@ -1214,21 +1216,19 @@ class Date
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if e._comp
|
e._compfunc ||= lambda do |y|
|
||||||
if e.cwyear
|
if e._comp
|
||||||
if e.cwyear >= 0 && e.cwyear <= 99
|
if y >= 0 && y <= 99
|
||||||
e.cwyear += if e.cwyear >= 69
|
y += if y >= 69
|
||||||
then 1900 else 2000 end
|
then 1900 else 2000 end
|
||||||
end
|
|
||||||
end
|
|
||||||
if e.year
|
|
||||||
if e.year >= 0 && e.year <= 99
|
|
||||||
e.year += if e.year >= 69
|
|
||||||
then 1900 else 2000 end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
y
|
||||||
end
|
end
|
||||||
|
|
||||||
|
e.cwyear = e._compfunc.call(e.cwyear) if e.cwyear
|
||||||
|
e. year = e._compfunc.call(e. year) if e. year
|
||||||
|
|
||||||
e.offset ||= zone_to_diff(e.zone) if e.zone
|
e.offset ||= zone_to_diff(e.zone) if e.zone
|
||||||
|
|
||||||
e.to_hash
|
e.to_hash
|
||||||
@ -1269,17 +1269,46 @@ class Date
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self._xmlschema(str) # :nodoc:
|
def self._xmlschema(str) # :nodoc:
|
||||||
if /\A\s*-?\d{4}-\d{2}-\d{2}
|
if /\A\s*(-?\d{4,})(?:-(\d{2})(?:-(\d{2}))?)?
|
||||||
(t
|
(?:t
|
||||||
\d{2}:\d{2}:\d{2}(?:\.\d+)?)?
|
(\d{2}):(\d{2}):(\d{2})(?:\.(\d+))?)?
|
||||||
(z|[-+]\d{2}:\d{2})?\s*\z/inx =~ str
|
(z|[-+]\d{2}:\d{2})?\s*\z/inx =~ str
|
||||||
if $1.nil? && $2
|
e = Format::Bag.new
|
||||||
str = str.sub(/(z|[-+]\d{2}:\d{2})/in, 'T00:00:00\1')
|
e.year = $1.to_i
|
||||||
|
e.mon = $2.to_i if $2
|
||||||
|
e.mday = $3.to_i if $3
|
||||||
|
e.hour = $4.to_i if $4
|
||||||
|
e.min = $5.to_i if $5
|
||||||
|
e.sec = $6.to_i if $6
|
||||||
|
e.sec_fraction = $7.to_i.to_r / (10**$7.size) if $7
|
||||||
|
if $8
|
||||||
|
e.zone = $8
|
||||||
|
e.offset = zone_to_diff($8)
|
||||||
end
|
end
|
||||||
_parse(str)
|
e.to_hash
|
||||||
elsif /\A\s*\d{2}:\d{2}:\d{2}(\.\d+)?
|
elsif /\A\s*(\d{2}):(\d{2}):(\d{2})(?:\.(\d+))?
|
||||||
(z|[-+]\d{2}:\d{2})?\s*\z/inx =~ str
|
(z|[-+]\d{2}:\d{2})?\s*\z/inx =~ str
|
||||||
_parse(str)
|
e = Format::Bag.new
|
||||||
|
e.hour = $1.to_i if $1
|
||||||
|
e.min = $2.to_i if $2
|
||||||
|
e.sec = $3.to_i if $3
|
||||||
|
e.sec_fraction = $4.to_i.to_r / (10**$4.size) if $4
|
||||||
|
if $5
|
||||||
|
e.zone = $5
|
||||||
|
e.offset = zone_to_diff($5)
|
||||||
|
end
|
||||||
|
e.to_hash
|
||||||
|
elsif /\A\s*(?:--(\d{2})(?:-(\d{2}))?|---(\d{2}))
|
||||||
|
(z|[-+]\d{2}:\d{2})?\s*\z/inx =~ str
|
||||||
|
e = Format::Bag.new
|
||||||
|
e.mon = $1.to_i if $1
|
||||||
|
e.mday = $2.to_i if $2
|
||||||
|
e.mday = $3.to_i if $3
|
||||||
|
if $4
|
||||||
|
e.zone = $4
|
||||||
|
e.offset = zone_to_diff($4)
|
||||||
|
end
|
||||||
|
e.to_hash
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1290,15 +1319,17 @@ class Date
|
|||||||
-?(\d{2,})\s+ # allow minus, anyway
|
-?(\d{2,})\s+ # allow minus, anyway
|
||||||
\d{2}:\d{2}(:\d{2})?\s*
|
\d{2}:\d{2}(:\d{2})?\s*
|
||||||
(?:[-+]\d{4}|ut|gmt|e[sd]t|c[sd]t|m[sd]t|p[sd]t|[a-ik-z])\s*\z/inox =~ str
|
(?:[-+]\d{4}|ut|gmt|e[sd]t|c[sd]t|m[sd]t|p[sd]t|[a-ik-z])\s*\z/inox =~ str
|
||||||
e = _parse(str, :comp=>false)
|
_parse(str, :compfunc=>
|
||||||
if $1.size < 4
|
lambda do |y|
|
||||||
if e[:year] < 50
|
if $1.size < 4
|
||||||
e[:year] += 2000
|
if y < 50
|
||||||
elsif e[:year] < 1000
|
y += 2000
|
||||||
e[:year] += 1900
|
elsif y < 1000
|
||||||
end
|
y += 1900
|
||||||
end
|
end
|
||||||
e
|
end
|
||||||
|
y
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user