summaryrefslogtreecommitdiff
path: root/lib/date
diff options
context:
space:
mode:
authortadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-09-01 15:47:52 +0000
committertadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-09-01 15:47:52 +0000
commitec6cf1f454eedfa541b113212426f26fcdec5c0d (patch)
tree967c55edc01c696b4b953de13138ce4f4144ef27 /lib/date
parentebef450d28ec493b53487ead5c2cfdbc0234c17b (diff)
* lib/date/format.rb (_parse): improved parsing of ordinal dates.
* lib/date/format.rb (_parse): use named character classes in some regular expressions. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13335 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/date')
-rw-r--r--lib/date/format.rb33
1 files changed, 21 insertions, 12 deletions
diff --git a/lib/date/format.rb b/lib/date/format.rb
index 32f4954cfa..810c59a4e8 100644
--- a/lib/date/format.rb
+++ b/lib/date/format.rb
@@ -1,5 +1,5 @@
# format.rb: Written by Tadayoshi Funaba 1999-2007
-# $Id: format.rb,v 2.36 2007-07-21 00:21:04+09 tadf Exp $
+# $Id: format.rb,v 2.38 2007-09-01 00:03:46+09 tadf Exp $
require 'rational'
@@ -540,8 +540,8 @@ class Date
e._cent ||= if val >= 69 then 19 else 20 end
when 'Z', /\A:{0,3}z/
return unless str.sub!(/\A((?:gmt|utc?)?[-+]\d+(?:[,.:]\d+(?::\d+)?)?
- |[a-z.\s]+(?:standard|daylight)\s+time\b
- |[a-z]+(?:\s+dst)?\b
+ |[[:alpha:].\s]+(?:standard|daylight)\s+time\b
+ |[[:alpha:]]+(?:\s+dst)?\b
)/ix, '')
val = $1
e.zone = val
@@ -595,6 +595,10 @@ class Date
m = m.to_s
end
+ if y && m && !d
+ y, m, d = d, y, m
+ end
+
if y == nil
if d && d.size > 2
y = d
@@ -690,9 +694,9 @@ class Date
(
(?:gmt|utc?)?[-+]\d+(?:[,.:]\d+(?::\d+)?)?
|
- [a-z.\s]+(?:standard|daylight)\stime\b
+ [[:alpha:].\s]+(?:standard|daylight)\stime\b
|
- [a-z]+(?:\sdst)?\b
+ [[:alpha:]]+(?:\sdst)?\b
)
)?
/inx,
@@ -803,10 +807,15 @@ class Date
e.mon = $1.to_i
e.mday = $2.to_i if $2
true
- elsif str.sub!(/\b(\d{2}|\d{4})?-(\d{3})\b/n, ' ')
- e.year = $1.to_i if $1
+ elsif /[,.](\d{2}|\d{4})-\d{3}\b/n !~ str &&
+ str.sub!(/\b(\d{2}|\d{4})-(\d{3})\b/n, ' ')
+ e.year = $1.to_i
e.yday = $2.to_i
true
+ elsif /\d-\d{3}\b/n !~ str &&
+ str.sub!(/\b-(\d{3})\b/n, ' ')
+ e.yday = $1.to_i
+ true
elsif e._date && str.sub!(/('?[-+]?\d+)-('?-?\d+)/n, ' ')
s3e(e, nil, $1, $2)
true
@@ -845,21 +854,21 @@ class Date
end
def self._parse_sla_jp(str, e) # :nodoc:
- if str.sub!(%r|('?-?\d+)/\s*('?\d+)(?:[^\d]\s*('?-?\d+))?|n, ' ') # '
+ if str.sub!(%r|('?-?\d+)/\s*('?\d+)(?:\D\s*('?-?\d+))?|n, ' ') # '
s3e(e, $1, $2, $3)
true
end
end
def self._parse_sla_eu(str, e) # :nodoc:
- if str.sub!(%r|('?-?\d+)/\s*('?\d+)(?:[^\d]\s*('?-?\d+))?|n, ' ') # '
+ if str.sub!(%r|('?-?\d+)/\s*('?\d+)(?:\D\s*('?-?\d+))?|n, ' ') # '
s3e(e, $3, $2, $1)
true
end
end
def self._parse_sla_us(str, e) # :nodoc:
- if str.sub!(%r|('?-?\d+)/\s*('?\d+)(?:[^\d]\s*('?-?\d+))?|n, ' ') # '
+ if str.sub!(%r|('?-?\d+)/\s*('?\d+)(?:\D\s*('?-?\d+))?|n, ' ') # '
s3e(e, $3, $1, $2)
true
end
@@ -896,7 +905,7 @@ class Date
end
def self._parse_year(str, e) # :nodoc:
- if str.sub!(/'(\d+)\b/in, ' ')
+ if str.sub!(/'(\d+)\b/n, ' ')
e.year = $1.to_i
true
end
@@ -1112,7 +1121,7 @@ class Date
end
end
- str.gsub!(/[^-+',.\/:0-9@a-z\[\]\x80-\xff]+/in, ' ')
+ str.gsub!(/[^-+',.\/:@[:alnum:]\[\]\x80-\xff]+/n, ' ')
case e._style
when :jp