Permalink
Browse files

add autfill year for fx

  • Loading branch information...
1 parent 36875bb commit e90d89be56a071a16fcd167def02b537da0e9ad5 @geraldb geraldb committed Sep 1, 2013
Showing with 35 additions and 12 deletions.
  1. +14 −4 lib/sportdb/reader.rb
  2. +20 −7 lib/sportdb/utils.rb
  3. +1 −1 lib/sportdb/version.rb
View
@@ -307,7 +307,7 @@ def load_event( name )
exit 1
end
- elsif key == 'start_at'
+ elsif key == 'start_at' || key == 'begin_at'
if value.is_a?(DateTime) || value.is_a?(Date)
start_at = value
@@ -316,7 +316,17 @@ def load_event( name )
end
event_attribs['start_at'] = start_at
+
+ elsif key == 'end_at' || key == 'stop_at'
+ if value.is_a?(DateTime) || value.is_a?(Date)
+ end_at = value
+ else # assume it's a string
+ end_at = DateTime.strptime( value.to_s.strip, '%Y-%m-%d' )
+ end
+
+ event_attribs['end_at'] = end_at
+
elsif key == 'teams'
## assume teams value is an array
@@ -768,12 +778,12 @@ def parse_game( line )
if is_postponed?( line )
postponed = true
- date_v2 = find_date!( line )
- date = find_date!( line )
+ date_v2 = find_date!( line, start_at: @event.start_at )
+ date = find_date!( line, start_at: @event.start_at )
else
postponed = false
date_v2 = nil
- date = find_date!( line )
+ date = find_date!( line, start_at: @event.start_at )
end
scores = find_scores!( line )
View
@@ -149,8 +149,23 @@ def find_round_pos!( line )
return nil
end
end # method find_round_pos!
-
- def find_date!( line )
+
+
+ def calculate_year( day, month, start_at )
+ if month >= start_at.month
+ # assume same year as start_at event (e.g. 2013 for 2013/14 season)
+ start_at.year
+ else
+ # assume year+1 as start_at event (e.g. 2014 for 2013/14 season)
+ start_at.year+1
+ end
+ end
+
+ def find_date!( line, opts={} )
+
+ ## NB: lets us pass in start_at/end_at date (for event)
+ # for auto-complete year
+
# extract date from line
# and return it
# NB: side effect - removes date from line string
@@ -211,12 +226,10 @@ def find_date!( line )
return DateTime.strptime( value, '%Y-%m-%d %H:%M' )
elsif line =~ regex_de
-
- #### fix/todo:
- # get year from event start date!!!!
- # do NOT hard code!!!!
- value = '2012-%02d-%02d %02d:%02d' % [$2.to_i, $1.to_i, $3.to_i, $4.to_i]
+ year = calculate_year( $1.to_i, $2.to_i, opts[:start_at] )
+
+ value = '%d-%02d-%02d %02d:%02d' % [year, $2.to_i, $1.to_i, $3.to_i, $4.to_i]
logger.debug " date: >#{value}<"
## todo: lets you configure year
View
@@ -1,6 +1,6 @@
module SportDb
- VERSION = '1.7.2'
+ VERSION = '1.7.3'
end

0 comments on commit e90d89b

Please sign in to comment.