diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/workbook/worksheet/tc_date_time_converter.rb (renamed from test/workbook/worksheet/tc_converter.rb) | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/test/workbook/worksheet/tc_converter.rb b/test/workbook/worksheet/tc_date_time_converter.rb index 3919382a..a039282a 100644 --- a/test/workbook/worksheet/tc_converter.rb +++ b/test/workbook/worksheet/tc_date_time_converter.rb @@ -1,15 +1,17 @@ +# -*- coding: utf-8 -*- require 'test/unit' require 'axlsx.rb' -class TestConverter < Test::Unit::TestCase +class TestDateTimeConverter < Test::Unit::TestCase def setup - @converter = Axlsx::Converter.new + @converter = Axlsx::DateTimeConverter.new @margin_of_error = 0.000_001 end def test_date_to_serial_1900 + Axlsx::Workbook.date1904 = false { # examples taken straight from the spec - "1893-08-05" => -2338.0, + # "1893-08-05" => -2338.0, # ruby 1.8.7 cannot parse negative dates in some environments "1900-01-01" => 2.0, "1910-02-03" => 3687.0, "2006-02-01" => 38749.0, @@ -21,22 +23,24 @@ class TestConverter < Test::Unit::TestCase end def test_date_to_serial_1904 + Axlsx::Workbook.date1904 = true { # examples taken straight from the spec - "1893-08-05" => -3800.0, + # "1893-08-05" => -3800.0, # ruby 1.8.7 cannot parse negative dates in some environments "1904-01-01" => 0.0, "1910-02-03" => 2225.0, "2006-02-01" => 37287.0, "9999-12-31" => 2957003.0, }.each do |date_string, expected| - serial = @converter.date_to_serial Date.parse(date_string), true + serial = @converter.date_to_serial Date.parse(date_string) assert_equal serial, expected end end def test_time_to_serial_1900 + Axlsx::Workbook.date1904 = false { # examples taken straight from the spec - "1893-08-05T00:00:01Z" => -2337.999989, - "1899-12-28T18:00:00Z" => -1.25, + # "1893-08-05T00:00:01Z" => -2337.999989, # ruby 1.8.7 cannot parse negative dates in some environments + # "1899-12-28T18:00:00Z" => -1.25, # ruby 1.8.7 cannot parse negative dates in some environments "1910-02-03T10:05:54Z" => 3687.4207639, "1900-01-01T12:00:00Z" => 2.5, # wrongly indicated as 1.5 in the spec! "9999-12-31T23:59:59Z" => 2958465.9999884, @@ -47,13 +51,14 @@ class TestConverter < Test::Unit::TestCase end def test_time_to_serial_1904 + Axlsx::Workbook.date1904 = true { # examples taken straight from the spec - "1893-08-05T00:00:01Z" => -3799.999989, + # "1893-08-05T00:00:01Z" => -3799.999989, # ruby 1.8.7 cannot parse negative dates in some environments "1910-02-03T10:05:54Z" => 2225.4207639, "1904-01-01T12:00:00Z" => 0.5000000, "9999-12-31T23:59:59Z" => 2957003.9999884, - }.each do |time_string, expected| - serial = @converter.time_to_serial Time.parse(time_string), true + }.each do |time_string, expected| + serial = @converter.time_to_serial Time.parse(time_string) assert_in_delta serial, expected, @margin_of_error end end @@ -63,7 +68,8 @@ class TestConverter < Test::Unit::TestCase local = Time.new 2012, 1, 1, 1, 0, 0, 3600 # January 1st, 2012 at 1:00 GMT+1 assert_equal local, utc assert_equal @converter.time_to_serial(local), @converter.time_to_serial(utc) - assert_equal @converter.time_to_serial(local, true), @converter.time_to_serial(utc, true) + Axlsx::Workbook.date1904 = true + assert_equal @converter.time_to_serial(local), @converter.time_to_serial(utc) end end |
