summaryrefslogtreecommitdiffstats
path: root/lib/roo/excelx/cell/date.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/roo/excelx/cell/date.rb')
-rw-r--r--lib/roo/excelx/cell/date.rb28
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/roo/excelx/cell/date.rb b/lib/roo/excelx/cell/date.rb
new file mode 100644
index 0000000..8e2c6cb
--- /dev/null
+++ b/lib/roo/excelx/cell/date.rb
@@ -0,0 +1,28 @@
+require 'date'
+
+module Roo
+ class Excelx
+ class Cell
+ class Date < Roo::Excelx::Cell::DateTime
+ attr_reader :value, :formula, :format, :cell_type, :cell_value, :link, :coordinate
+
+ def initialize(value, formula, excelx_type, style, link, base_date, coordinate)
+ # NOTE: Pass all arguments to the parent class, DateTime.
+ super
+ @type = :date
+ @format = excelx_type.last
+ @value = link? ? Roo::Link.new(link, value) : create_date(base_date, value)
+ end
+
+ private
+
+ def create_date(base_date, value)
+ date = base_date + value.to_i
+ yyyy, mm, dd = date.strftime('%Y-%m-%d').split('-')
+
+ ::Date.new(yyyy.to_i, mm.to_i, dd.to_i)
+ end
+ end
+ end
+ end
+end