Skip to content

Commit

Permalink
issue-310 off by one error
Browse files Browse the repository at this point in the history
correct comment

correct comment

correct comment
  • Loading branch information
OldRugger committed Dec 27, 2019
1 parent 4ec1104 commit f56addc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/roo/excelx/cell/time.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def initialize(value, formula, excelx_type, style, link, base_date, coordinate)
super
@format = excelx_type.last
@datetime = create_datetime(base_date, value)
@value = link ? Roo::Link.new(link, value) : (value.to_f * 86_400).to_i
@value = link ? Roo::Link.new(link, value) : (value.to_f * 86_400).round.to_i
end

def formatted_value
Expand Down
15 changes: 15 additions & 0 deletions spec/lib/roo/excelx/cell/time_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require 'spec_helper'

RSpec.describe Roo::Excelx::Cell::Time do
it "should set the cell value to the correct number of seconds" do
value = 0.05513888888888888 # '1:19:24'
excelx_type = [:numeric_or_formula, "h:mm:ss"]
base_timestamp = Date.new(1899, 12, 30).to_time.to_i
time_cell = Roo::Excelx::Cell::Time.new(value, nil, excelx_type, 1, nil, base_timestamp, nil)
expect(time_cell.value).to eq(1*60*60 + 19*60 + 24) # '1:19:24' in seconds
# use case from https://github.com/roo-rb/roo/issues/310
value = 0.523761574074074 # '12:34:13' in seconds
time_cell = Roo::Excelx::Cell::Time.new(value, nil, excelx_type, 1, nil, base_timestamp, nil)
expect(time_cell.value).to eq(12*60*60 + 34*60 + 13) # 12:34:13 in seconds
end
end

0 comments on commit f56addc

Please sign in to comment.