Permalink
Browse files

add new date format en2

  • Loading branch information...
1 parent 77813ce commit af6fc659596337f07ac1ea6164457aa728734f78 @geraldb geraldb committed Dec 17, 2013
Showing with 42 additions and 1 deletion.
  1. +30 −0 lib/sportdb/utils.rb
  2. +1 −1 lib/sportdb/version.rb
  3. +11 −0 test/test_date.rb
View
@@ -200,6 +200,10 @@ def find_date!( line, opts={} )
# e.g. 12 May 2013 14:00 => D|DD.MMM.YYYY H|HH:MM
regex_en = /\b(\d{1,2})\s(#{month_abbrev_en})\s(\d{4})\s+(\d{1,2}):(\d{2})\b/
+ ## todo: add version w/ hours
+ # e.g. Jun/12 w/ implied year and implied hours (set to 12:00)
+ regex_en2 = /\b(#{month_abbrev_en})\/(\d{1,2})\b/
+
if line =~ regex_db
value = '%d-%02d-%02d %02d:%02d' % [$1.to_i, $2.to_i, $3.to_i, $4.to_i, $5.to_i]
@@ -276,6 +280,32 @@ def find_date!( line, opts={} )
line.sub!( regex_en, '[DATE.EN]' )
return DateTime.strptime( value, '%Y-%b-%d %H:%M' ) ## %b - abbreviated month name (e.g. Jan,Feb, etc.)
+ elsif line =~ regex_en2
+ # todo: make more generic for reuse
+ month_abbrev_en_to_i = {
+ 'Jan' => 1,
+ 'Feb' => 2,
+ 'Mar' => 3,
+ 'Apr' => 4,
+ 'May' => 5,
+ 'Jun' => 6,
+ 'Jul' => 7,
+ 'Aug' => 8,
+ 'Sep' => 9,
+ 'Oct' => 10,
+ 'Nov' => 11,
+ 'Dec' => 12 }
+
+ day = $2.to_i
+ month = month_abbrev_en_to_i[ $1 ]
+ year = calculate_year( day, month, opts[:start_at] )
+
+ value = '%d-%02d-%02d 12:00' % [year, month, day]
+ logger.debug " date: >#{value}<"
+
+ line.sub!( regex_en2, '[DATE.EN2] ' )
+
+ return DateTime.strptime( value, '%Y-%m-%d %H:%M' )
else
return nil
end
View
@@ -1,6 +1,6 @@
module SportDb
- VERSION = '1.7.7'
+ VERSION = '1.7.8'
end
View
@@ -11,6 +11,17 @@ def test_date
assert_date DateTime.new( 2013, 1, 26 ), parse_date( '26.01.2013' )
end
+ def test_date_en
+ start_at = DateTime.new( 2013, 1, 25 )
+
+ assert_date DateTime.new( 2013, 1, 26 ), parse_date( 'Jan/26', start_at: start_at )
+ assert_datetime DateTime.new( 2013, 1, 26, 12, 00 ), parse_date( 'Jan/26', start_at: start_at )
+
+ assert_date DateTime.new( 2013, 6, 13 ), parse_date( 'Jun/13', start_at: start_at )
+ assert_datetime DateTime.new( 2013, 6, 13, 12, 00 ), parse_date( 'Jun/13', start_at: start_at )
+ end
+
+
private
## todo: check if assert_datetime or assert_date exist already? what is the best practice to check dates ???

0 comments on commit af6fc65

Please sign in to comment.