From 6683940715a917e79050e01e0f02c9642c8ffa00 Mon Sep 17 00:00:00 2001 From: tadf Date: Fri, 20 Jul 2007 16:52:59 +0000 Subject: * lib/date/format.rb (Date._parse): completes calendar week based year. * lib/date/format.rb (Date._parse): detects year of ordinal date in extended format. * and some trivial adjustments. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12824 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/date/format.rb | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) (limited to 'lib/date') diff --git a/lib/date/format.rb b/lib/date/format.rb index e2339827c5..b943822597 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.35 2007-05-19 09:23:48+09 tadf Exp $ +# $Id: format.rb,v 2.36 2007-07-21 00:21:04+09 tadf Exp $ require 'rational' @@ -652,7 +652,7 @@ class Date private_class_method :s3e def self._parse_day(str, e) # :nodoc: - if str.sub!(/\b(#{Format::ABBR_DAYS.keys.join('|')})[^-\d\s]*/ino, ' ') + if str.sub!(/\b(#{Format::ABBR_DAYS.keys.join('|')})[^-\d\s]*/in, ' ') e.wday = Format::ABBR_DAYS[$1.downcase] true =begin @@ -748,7 +748,7 @@ class Date \s* ('?-?\d+(?:(?:st|nd|rd|th)\b)?) )? - /inox, + /inx, ' ') # ' s3e(e, $4, Format::ABBR_MONTHS[$2.downcase], $1, $3 && $3[0,1].downcase == 'b') @@ -767,7 +767,7 @@ class Date \s* ('?-?\d+) )? - /inox, + /inx, ' ') # ' s3e(e, $4, Format::ABBR_MONTHS[$1.downcase], $2, $3 && $3[0,1].downcase == 'b') @@ -789,7 +789,7 @@ class Date e.cwday = $3.to_i if $3 true elsif str.sub!(/-w-(\d)\b/in, ' ') - e.cwday = $1.to_i + e.cwday = $1.to_i true elsif str.sub!(/--(\d{2})?-(\d{2})\b/n, ' ') e.mon = $1.to_i if $1 @@ -799,14 +799,15 @@ class Date e.mon = $1.to_i e.mday = $2.to_i if $2 true - elsif str.sub!(/-(\d{3})\b/n, ' ') - e.yday = $1.to_i + elsif str.sub!(/\b(\d{2}|\d{4})?-(\d{3})\b/n, ' ') + e.year = $1.to_i if $1 + e.yday = $2.to_i true end end def self._parse_jis(str, e) # :nodoc: - if str.sub!(/\b([MTSH])(\d+)\.(\d+)\.(\d+)/in, ' ') + if str.sub!(/\b([mtsh])(\d+)\.(\d+)\.(\d+)/in, ' ') era = { 'm'=>1867, 't'=>1911, 's'=>1925, @@ -821,11 +822,11 @@ class Date def self._parse_vms(str, e) # :nodoc: if str.sub!(/('?-?\d+)-(#{Format::ABBR_MONTHS.keys.join('|')})[^-]* - -('?-?\d+)/inox, ' ') + -('?-?\d+)/inx, ' ') s3e(e, $3, Format::ABBR_MONTHS[$2.downcase], $1) true elsif str.sub!(/\b(#{Format::ABBR_MONTHS.keys.join('|')})[^-]* - -('?-?\d+)(?:-('?-?\d+))?/inox, ' ') + -('?-?\d+)(?:-('?-?\d+))?/inx, ' ') s3e(e, $3, Format::ABBR_MONTHS[$1.downcase], $2) true end @@ -853,7 +854,7 @@ class Date end def self._parse_mon(str, e) # :nodoc: - if str.sub!(/\b(#{Format::ABBR_MONTHS.keys.join('|')})\S*/ino, ' ') + if str.sub!(/\b(#{Format::ABBR_MONTHS.keys.join('|')})\S*/in, ' ') e.mon = Format::ABBR_MONTHS[$1.downcase] true end @@ -1050,12 +1051,17 @@ class Date end end - if e._comp && e.year - if e.year >= 0 && e.year <= 99 - if e.year >= 69 - e.year += 1900 - else - e.year += 2000 + if e._comp + if e.cwyear + if e.cwyear >= 0 && e.cwyear <= 99 + e.cwyear += if e.cwyear >= 69 + 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 -- cgit v1.2.3