summaryrefslogtreecommitdiff
path: root/ext/date/lib
diff options
context:
space:
mode:
authortadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-04-16 12:58:28 +0000
committertadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-04-16 12:58:28 +0000
commitec01a8813ffe941220a6c77ee6f57a29f391501b (patch)
treeb0947a7217f1b981abdde0b50aa512502c602908 /ext/date/lib
parentb1fd9e92152c6da896e3d7977ef730db2b1ad670 (diff)
* ext/date/date_core.c: replacement of implementation of
_strptime. [experimental] * ext/date/date_strptime.c: new. * ext/date/lib/date/format.rb: removed ruby version of _strptime. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31295 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/date/lib')
-rw-r--r--ext/date/lib/date/format.rb219
1 files changed, 0 insertions, 219 deletions
diff --git a/ext/date/lib/date/format.rb b/ext/date/lib/date/format.rb
index d38525b7e3..00fcb363ef 100644
--- a/ext/date/lib/date/format.rb
+++ b/ext/date/lib/date/format.rb
@@ -179,221 +179,6 @@ class Date
end
=end
- def self.num_pattern? (s) # :nodoc:
- /\A%[EO]?[CDdeFGgHIjkLlMmNQRrSsTUuVvWwXxYy\d]/ =~ s || /\A\d/ =~ s
- end
-
- private_class_method :num_pattern?
-
- def self._strptime_i(str, fmt, e) # :nodoc:
- fmt.scan(/%([EO]?(?::{1,3}z|.))|(.)/m) do |s, c|
- a = $&
- if s
- case s
- when 'A', 'a'
- return unless str.sub!(/\A(#{Format::DAYS.keys.join('|')})/io, '') ||
- str.sub!(/\A(#{Format::ABBR_DAYS.keys.join('|')})/io, '')
- val = Format::DAYS[$1.downcase] || Format::ABBR_DAYS[$1.downcase]
- return unless val
- e.wday = val
- when 'B', 'b', 'h'
- return unless str.sub!(/\A(#{Format::MONTHS.keys.join('|')})/io, '') ||
- str.sub!(/\A(#{Format::ABBR_MONTHS.keys.join('|')})/io, '')
- val = Format::MONTHS[$1.downcase] || Format::ABBR_MONTHS[$1.downcase]
- return unless val
- e.mon = val
- when 'C', 'EC'
- return unless str.sub!(if num_pattern?($')
- then /\A([-+]?\d{1,2})/
- else /\A([-+]?\d{1,})/
- end, '')
- val = $1.to_i
- e._cent = val
- when 'c', 'Ec'
- return unless _strptime_i(str, '%a %b %e %H:%M:%S %Y', e)
- when 'D'
- return unless _strptime_i(str, '%m/%d/%y', e)
- when 'd', 'e', 'Od', 'Oe'
- return unless str.sub!(/\A( \d|\d{1,2})/, '')
- val = $1.to_i
- return unless (1..31) === val
- e.mday = val
- when 'F'
- return unless _strptime_i(str, '%Y-%m-%d', e)
- when 'G'
- return unless str.sub!(if num_pattern?($')
- then /\A([-+]?\d{1,4})/
- else /\A([-+]?\d{1,})/
- end, '')
- val = $1.to_i
- e.cwyear = val
- when 'g'
- return unless str.sub!(/\A(\d{1,2})/, '')
- val = $1.to_i
- return unless (0..99) === val
- e.cwyear = val
- e._cent ||= if val >= 69 then 19 else 20 end
- when 'H', 'k', 'OH'
- return unless str.sub!(/\A( \d|\d{1,2})/, '')
- val = $1.to_i
- return unless (0..24) === val
- e.hour = val
- when 'I', 'l', 'OI'
- return unless str.sub!(/\A( \d|\d{1,2})/, '')
- val = $1.to_i
- return unless (1..12) === val
- e.hour = val
- when 'j'
- return unless str.sub!(/\A(\d{1,3})/, '')
- val = $1.to_i
- return unless (1..366) === val
- e.yday = val
- when 'L'
- return unless str.sub!(if num_pattern?($')
- then /\A([-+]?\d{1,3})/
- else /\A([-+]?\d{1,})/
- end, '')
-# val = Rational($1.to_i, 10**3)
- val = Rational($1.to_i, 10**$1.size)
- e.sec_fraction = val
- when 'M', 'OM'
- return unless str.sub!(/\A(\d{1,2})/, '')
- val = $1.to_i
- return unless (0..59) === val
- e.min = val
- when 'm', 'Om'
- return unless str.sub!(/\A(\d{1,2})/, '')
- val = $1.to_i
- return unless (1..12) === val
- e.mon = val
- when 'N'
- return unless str.sub!(if num_pattern?($')
- then /\A([-+]?\d{1,9})/
- else /\A([-+]?\d{1,})/
- end, '')
-# val = Rational($1.to_i, 10**9)
- val = Rational($1.to_i, 10**$1.size)
- e.sec_fraction = val
- when 'n', 't'
- return unless _strptime_i(str, "\s", e)
- when 'P', 'p'
- return unless str.sub!(/\A([ap])(?:m\b|\.m\.)/i, '')
- e._merid = if $1.downcase == 'a' then 0 else 12 end
- when 'Q'
- return unless str.sub!(/\A(-?\d{1,})/, '')
- val = Rational($1.to_i, 10**3)
- e.seconds = val
- when 'R'
- return unless _strptime_i(str, '%H:%M', e)
- when 'r'
- return unless _strptime_i(str, '%I:%M:%S %p', e)
- when 'S', 'OS'
- return unless str.sub!(/\A(\d{1,2})/, '')
- val = $1.to_i
- return unless (0..60) === val
- e.sec = val
- when 's'
- return unless str.sub!(/\A(-?\d{1,})/, '')
- val = $1.to_i
- e.seconds = val
- when 'T'
- return unless _strptime_i(str, '%H:%M:%S', e)
- when 'U', 'W', 'OU', 'OW'
- return unless str.sub!(/\A(\d{1,2})/, '')
- val = $1.to_i
- return unless (0..53) === val
- e.__send__(if s[-1,1] == 'U' then :wnum0= else :wnum1= end, val)
- when 'u', 'Ou'
- return unless str.sub!(/\A(\d{1})/, '')
- val = $1.to_i
- return unless (1..7) === val
- e.cwday = val
- when 'V', 'OV'
- return unless str.sub!(/\A(\d{1,2})/, '')
- val = $1.to_i
- return unless (1..53) === val
- e.cweek = val
- when 'v'
- return unless _strptime_i(str, '%e-%b-%Y', e)
- when 'w'
- return unless str.sub!(/\A(\d{1})/, '')
- val = $1.to_i
- return unless (0..6) === val
- e.wday = val
- when 'X', 'EX'
- return unless _strptime_i(str, '%H:%M:%S', e)
- when 'x', 'Ex'
- return unless _strptime_i(str, '%m/%d/%y', e)
- when 'Y', 'EY'
- return unless str.sub!(if num_pattern?($')
- then /\A([-+]?\d{1,4})/
- else /\A([-+]?\d{1,})/
- end, '')
- val = $1.to_i
- e.year = val
- when 'y', 'Ey', 'Oy'
- return unless str.sub!(/\A(\d{1,2})/, '')
- val = $1.to_i
- return unless (0..99) === val
- e.year = val
- 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+)?)?
- |[[:alpha:].\s]+(?:standard|daylight)\s+time\b
- |[[:alpha:]]+(?:\s+dst)?\b
- )/ix, '')
- val = $1
- e.zone = val
- offset = zone_to_diff(val)
- e.offset = offset
- when '%'
- return unless str.sub!(/\A%/, '')
- when '+'
- return unless _strptime_i(str, '%a %b %e %H:%M:%S %Z %Y', e)
- else
- return unless str.sub!(Regexp.new('\\A' + Regexp.quote(a)), '')
- end
- else
- case c
- when /\A\s/
- str.sub!(/\A\s+/, '')
- else
- return unless str.sub!(Regexp.new('\\A' + Regexp.quote(a)), '')
- end
- end
- end
- end
-
- private_class_method :_strptime_i
-
- def self._strptime(str, fmt='%F')
- str = str.dup
- e = Format::Bag.new
- return unless _strptime_i(str, fmt, e)
-
- if e._cent
- if e.cwyear
- e.cwyear += e._cent * 100
- end
- if e.year
- e. year += e._cent * 100
- end
- end
-
- if e._merid
- if e.hour
- e.hour %= 12
- e.hour += e._merid
- end
- end
-
- unless str.empty?
- e.leftover = str
- end
-
- e.to_hash
- end
-
def self.s3e(e, y, m, d, bc=false)
unless String === m
m = m.to_s
@@ -1073,10 +858,6 @@ end
class DateTime < Date
- def self._strptime(str, fmt='%FT%T%z')
- super(str, fmt)
- end
-
def iso8601_timediv(n) # :nodoc:
strftime('T%T' +
if n < 1