aboutsummaryrefslogtreecommitdiffstats
path: root/lib/parsedate.rb
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1998-01-16 12:13:05 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1998-01-16 12:13:05 +0000
commit3db12e8b236ac8f88db8eb4690d10e4a3b8dbcd4 (patch)
treeb3c086e437cab449f90ba637710daed0ddfec4c4 /lib/parsedate.rb
parent392296c12de9d7f9be03a8205250ba0844cb9d38 (diff)
downloadruby-3db12e8b236ac8f88db8eb4690d10e4a3b8dbcd4.tar.gz
Initial revisionv1_0_r2
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/parsedate.rb')
-rw-r--r--lib/parsedate.rb42
1 files changed, 42 insertions, 0 deletions
diff --git a/lib/parsedate.rb b/lib/parsedate.rb
new file mode 100644
index 0000000000..1c1dda76bc
--- /dev/null
+++ b/lib/parsedate.rb
@@ -0,0 +1,42 @@
+module ParseDate
+ MONTHS = {
+ 'jan' => 1, 'feb' => 2, 'mar' => 3, 'apr' => 4,
+ 'may' => 5, 'jun' => 6, 'jul' => 7, 'aug' => 8,
+ 'sep' => 9, 'oct' =>10, 'nov' =>11, 'dec' =>12 }
+ MONTHPAT = MONTHS.keys.join('|')
+ DAYPAT = 'mon|tue|wed|thu|fri|sat|sun'
+
+ def parsedate(date)
+ if date.sub!(/(#{DAYPAT})/i, ' ')
+ dayofweek = $1
+ end
+ if date.sub!(/\s+(\d+:\d+(:\d+)?)/, ' ')
+ time = $1
+ end
+ if date =~ /19(\d\d)/
+ year = Integer($1)
+ end
+ if date.sub!(/\s*(\d+)\s+(#{MONTHPAT})\S*\s+/i, ' ')
+ dayofmonth = $1.to_i
+ monthname = $2
+ elsif date.sub!(/\s*(#{MONTHPAT})\S*\s+(\d+)\s+/i, ' ')
+ monthname = $1
+ dayofmonth = $2.to_i
+ elsif date.sub!(/\s*(#{MONTHPAT})\S*\s+(\d+)\D+/i, ' ')
+ monthname = $1
+ dayofmonth = $2.to_i
+ elsif date.sub!(/\s*(\d\d?)\/(\d\d?)/, ' ')
+ month = $1
+ dayofmonth = $2.to_i
+ end
+ if monthname
+ month = MONTHS[monthname.downcase]
+ end
+ if ! year && date =~ /\d\d/
+ year = Integer($&)
+ end
+ return year, month, dayofmonth
+ end
+
+ module_function :parsedate
+end