From 3eb884c66fb5bec380412dd4ff23aa5360eb1c5f Mon Sep 17 00:00:00 2001 From: Akshay Vashishtha Date: Thu, 22 Jun 2023 13:52:29 +0530 Subject: [PATCH 1/3] added parsing logic when excel sheet use custom data-type as yyyy-mm-dd --- lib/roo/excelx/cell/date.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/roo/excelx/cell/date.rb b/lib/roo/excelx/cell/date.rb index 8627bc57..7a7cb060 100644 --- a/lib/roo/excelx/cell/date.rb +++ b/lib/roo/excelx/cell/date.rb @@ -1,4 +1,5 @@ require 'date' +require 'byebug' module Roo class Excelx @@ -20,7 +21,17 @@ def initialize(value, formula, excelx_type, style, link, base_date, coordinate) def create_datetime(_,_); end def create_date(base_date, value) - base_date + value.to_i + if contains_only_digits(value) + base_date + value.to_i + else + ::Date.parse(value) + end + end + + def contains_only_digits(string) + pattern = /^(\.|\d+(\.\d+)?)$/ + string = string.to_s unless string.is_a?(String) + !!(string.match?(pattern)) end end end From 97813c48291625f1a3f3c66ecbb773da33e60bfb Mon Sep 17 00:00:00 2001 From: Akshay Vashishtha Date: Thu, 22 Jun 2023 13:53:40 +0530 Subject: [PATCH 2/3] removed byebug --- lib/roo/excelx/cell/date.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/roo/excelx/cell/date.rb b/lib/roo/excelx/cell/date.rb index 7a7cb060..f3475290 100644 --- a/lib/roo/excelx/cell/date.rb +++ b/lib/roo/excelx/cell/date.rb @@ -1,5 +1,4 @@ require 'date' -require 'byebug' module Roo class Excelx From 7732ee32d43b616015d69b1aad18ddcbd3e52aac Mon Sep 17 00:00:00 2001 From: Akshay Vashishtha Date: Thu, 22 Jun 2023 16:55:31 +0530 Subject: [PATCH 3/3] removed double bang instead using ? for boolean values --- lib/roo/excelx/cell/date.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/roo/excelx/cell/date.rb b/lib/roo/excelx/cell/date.rb index f3475290..06689559 100644 --- a/lib/roo/excelx/cell/date.rb +++ b/lib/roo/excelx/cell/date.rb @@ -30,7 +30,7 @@ def create_date(base_date, value) def contains_only_digits(string) pattern = /^(\.|\d+(\.\d+)?)$/ string = string.to_s unless string.is_a?(String) - !!(string.match?(pattern)) + (string.match?(pattern)) end end end