summaryrefslogtreecommitdiffhomepage
path: root/test/workbook/worksheet/tc_date_time_converter.rb
diff options
context:
space:
mode:
authorRandy Morgan <[email protected]>2012-02-23 10:09:17 +0900
committerRandy Morgan <[email protected]>2012-02-23 10:09:17 +0900
commit42b3af1a8b6e6a68c200f40d35e0dbad5b7316c3 (patch)
tree791ab1dab81554b730b1f53b1f4ec48d5924f1a2 /test/workbook/worksheet/tc_date_time_converter.rb
parent65ec495117d22df16ef1c3fc94bdcfe0f2d32d30 (diff)
downloadcaxlsx-42b3af1a8b6e6a68c200f40d35e0dbad5b7316c3.tar.gz
caxlsx-42b3af1a8b6e6a68c200f40d35e0dbad5b7316c3.zip
ruby version conditional specs to deal with epoc issues
http://ruby-doc.org/core-1.8.7/Time.html
Diffstat (limited to 'test/workbook/worksheet/tc_date_time_converter.rb')
-rw-r--r--test/workbook/worksheet/tc_date_time_converter.rb92
1 files changed, 62 insertions, 30 deletions
diff --git a/test/workbook/worksheet/tc_date_time_converter.rb b/test/workbook/worksheet/tc_date_time_converter.rb
index a039282a..9bc5b311 100644
--- a/test/workbook/worksheet/tc_date_time_converter.rb
+++ b/test/workbook/worksheet/tc_date_time_converter.rb
@@ -9,42 +9,65 @@ class TestDateTimeConverter < Test::Unit::TestCase
end
def test_date_to_serial_1900
- Axlsx::Workbook.date1904 = false
- { # examples taken straight from the spec
- # "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,
- "9999-12-31" => 2958465.0,
- }.each do |date_string, expected|
+ Axlsx::Workbook.date1904 = false
+ tests = if RUBY_VERSION == '1.8.7'
+ { # examples taken straight from the spec
+ "2006-02-01" => 38749.0,
+ "9999-12-31" => 2958465.0
+ }
+ else
+ {
+ "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,
+ "9999-12-31" => 2958465.0
+ }
+ end
+ tests.each do |date_string, expected|
serial = @converter.date_to_serial Date.parse(date_string)
assert_equal serial, expected
end
end
def test_date_to_serial_1904
- Axlsx::Workbook.date1904 = true
- { # examples taken straight from the spec
- # "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|
+ Axlsx::Workbook.date1904 = true
+ tests = if RUBY_VERSION == '1.8.7'
+ { # examples taken straight from the spec
+ "2006-02-01" => 37287.0,
+ "9999-12-31" => 2957003.0
+ }
+ else
+ {
+ "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
+ }
+ end
+ tests.each do |date_string, expected|
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, # 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,
- }.each do |time_string, expected|
+ Axlsx::Workbook.date1904 = false
+ tests = if RUBY_VERSION == '1.8.7'
+ {
+ "9999-12-31T23:59:59Z" => 2958465.9999884
+ }
+ else
+ {
+ "1893-08-05T00:00:01Z" => -2337.999989,
+ "1899-12-28T18:00:00Z" => -1.25,
+ "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
+ }
+ end
+ tests.each do |time_string, expected|
serial = @converter.time_to_serial Time.parse(time_string)
assert_in_delta serial, expected, @margin_of_error
end
@@ -52,12 +75,21 @@ class TestDateTimeConverter < Test::Unit::TestCase
def test_time_to_serial_1904
Axlsx::Workbook.date1904 = true
- { # examples taken straight from the spec
- # "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|
+ # ruby 1.8.7 cannot parse dates prior to epoc. see http://ruby-doc.org/core-1.8.7/Time.html
+
+ tests = if RUBY_VERSION == '1.8.7'
+ { # examples taken straight from the spec
+ "9999-12-31T23:59:59Z" => 2957003.9999884,
+ }
+ else
+ { # examples taken straight from the spec
+ "1893-08-05T00:00:01Z" => -3799.999989,
+ "1910-02-03T10:05:54Z" => 2225.4207639,
+ "1904-01-01T12:00:00Z" => 0.5000000,
+ "9999-12-31T23:59:59Z" => 2957003.9999884
+ }
+ end
+ tests.each do |time_string, expected|
serial = @converter.time_to_serial Time.parse(time_string)
assert_in_delta serial, expected, @margin_of_error
end