Skip to content

Commit

Permalink
Fix an off-by-one error when reading dates
Browse files Browse the repository at this point in the history
  • Loading branch information
Hannes Wyss authored and hannes-wyss committed Jul 3, 2009
1 parent cf398b1 commit e13c616
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions lib/spreadsheet/excel/row.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ def _date data # :nodoc:
end
def _datetime data # :nodoc:
return data if data.is_a?(DateTime)
date = @worksheet.date_base + data.to_f
if date > LEAP_ERROR
base = @worksheet.date_base
date = base + data.to_f
if LEAP_ERROR > base
date -= 1
end
date
Expand Down
5 changes: 3 additions & 2 deletions lib/spreadsheet/excel/writer/worksheet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ def encode_date date
date = DateTime.new date.year, date.month, date.day,
date.hour, date.min, date.sec
end
value = date - @workbook.date_base
if date > LEAP_ERROR
base = @workbook.date_base
value = date - base
if LEAP_ERROR > base
value += 1
end
value
Expand Down

0 comments on commit e13c616

Please sign in to comment.