diff options
| author | Jonathan Tron <[email protected]> | 2015-07-04 12:23:20 +0200 |
|---|---|---|
| committer | Jonathan Tron <[email protected]> | 2015-07-04 12:23:20 +0200 |
| commit | 7e27afaa893bbef05faa541e9e87195d5ebafb0c (patch) | |
| tree | 481a3513d11db2928335d5a32dbdee17bc98b596 | |
| parent | 72212c1f4033ae2de83253306a246b5161e07428 (diff) | |
| parent | 2c2cb92009bd3c1d73b24fc4ffd71d3bacb0102b (diff) | |
| download | caxlsx-7e27afaa893bbef05faa541e9e87195d5ebafb0c.tar.gz caxlsx-7e27afaa893bbef05faa541e9e87195d5ebafb0c.zip | |
Merge branch 'soutaro-fix-time-cast'
| -rw-r--r-- | lib/axlsx/workbook/worksheet/cell.rb | 6 | ||||
| -rw-r--r-- | test/workbook/worksheet/tc_cell.rb | 13 |
2 files changed, 18 insertions, 1 deletions
diff --git a/lib/axlsx/workbook/worksheet/cell.rb b/lib/axlsx/workbook/worksheet/cell.rb index cd9e1829..3136d0e0 100644 --- a/lib/axlsx/workbook/worksheet/cell.rb +++ b/lib/axlsx/workbook/worksheet/cell.rb @@ -452,7 +452,11 @@ module Axlsx v when :time self.style = STYLE_DATE if self.style == 0 - v.respond_to?(:to_time) ? v.to_time : v + if !v.is_a?(Time) && v.respond_to?(:to_time) + v.to_time + else + v + end when :float v.to_f when :integer diff --git a/test/workbook/worksheet/tc_cell.rb b/test/workbook/worksheet/tc_cell.rb index f9761330..5ae2a51f 100644 --- a/test/workbook/worksheet/tc_cell.rb +++ b/test/workbook/worksheet/tc_cell.rb @@ -119,6 +119,19 @@ class TestCell < Test::Unit::TestCase assert_equal("2012-10-10T12:24", @c.send(:cast_value, "2012-10-10T12:24")) end + def test_cast_time_subclass + subtime = Class.new(Time) do + def to_time + raise "#to_time of Time subclass should not be called" + end + end + + time = subtime.now + + @c.type = :time + assert_equal(time, @c.send(:cast_value, time)) + end + def test_color assert_raise(ArgumentError) { @c.color = -1.1 } assert_nothing_raised { @c.color = "FF00FF00" } |
