Browse files

add new date regex

  • Loading branch information...
1 parent 44115c1 commit 31bceb7996b576fc6c06a017c456e85fb6140f3b @geraldb geraldb committed Sep 16, 2013
Showing with 17 additions and 1 deletion.
  1. +16 −0 lib/sportdb/utils.rb
  2. +1 −1 lib/sportdb/version.rb
View
16 lib/sportdb/utils.rb
@@ -191,6 +191,9 @@ def find_date!( line, opts={} )
# e.g. 14.09.2012 => DD.MM.YYYY w/ implied hours (set to 12:00)
regex_de3 = /\b(\d{1,2})\.(\d{1,2})\.(\d{4})\b/
+ # e.g. 14.09. => DD.MM. w/ implied year and implied hours (set to 12:00)
+ regex_de4 = /\b(\d{1,2})\.(\d{1,2})\.\s+/
+
month_abbrev_en = "Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec"
@@ -248,6 +251,19 @@ def find_date!( line, opts={} )
line.sub!( regex_de3, '[DATE.DE3]' )
return DateTime.strptime( value, '%Y-%m-%d %H:%M' )
+ elsif line =~ regex_de4
+
+ year = calculate_year( $1.to_i, $2.to_i, opts[:start_at] )
+
+ value = '%d-%02d-%02d 12:00' % [year, $2.to_i, $1.to_i]
+ logger.debug " date: >#{value}<"
+
+ ## todo: lets you configure year
+ ## and time zone (e.g. cet, eet, utc, etc.)
+
+ line.sub!( regex_de4, '[DATE.DE4]' )
+
+ return DateTime.strptime( value, '%Y-%m-%d %H:%M' )
elsif line =~ regex_en
value = '%d-%s-%02d %02d:%02d' % [$3.to_i, $2, $1.to_i, $4.to_i, $5.to_i]
logger.debug " date: >#{value}<"
View
2 lib/sportdb/version.rb
@@ -1,6 +1,6 @@
module SportDb
- VERSION = '1.7.3'
+ VERSION = '1.7.4'
end

0 comments on commit 31bceb7

Please sign in to comment.