File: test_date.rb

package info (click to toggle)
ruby-roo 3.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 8,216 kB
  • sloc: ruby: 6,529; xml: 88; makefile: 6
file content (38 lines) | stat: -rw-r--r-- 1,108 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
require 'test_helper'

class TestRooExcelxCellDate < Minitest::Test
  def date_cell
    Roo::Excelx::Cell::Date
  end

  def base_date
    ::Date.new(1899, 12, 30)
  end

  def base_date_1904
    ::Date.new(1904, 01, 01)
  end

  def test_handles_1904_base_date
    cell = date_cell.new('41791', nil, [:numeric_or_formula, 'mm-dd-yy'], 6, nil, base_date_1904, nil)
    assert_equal ::Date.new(2018, 06, 02), cell.value
  end

  def test_formatted_value
    cell = date_cell.new('41791', nil, [:numeric_or_formula, 'mm-dd-yy'], 6, nil, base_date, nil)
    assert_equal '06-01-14', cell.formatted_value

    cell = date_cell.new('41791', nil, [:numeric_or_formula, 'yyyy-mm-dd'], 6, nil, base_date, nil)
    assert_equal '2014-06-01', cell.formatted_value
  end

  def test_value_is_date
    cell = date_cell.new('41791', nil, [:numeric_or_formula, 'mm-dd-yy'], 6, nil, base_date, nil)
    assert_kind_of ::Date, cell.value
  end

  def test_value
    cell = date_cell.new('41791', nil, [:numeric_or_formula, 'mm-dd-yy'], 6, nil, base_date, nil)
    assert_equal ::Date.new(2014, 06, 01), cell.value
  end
end