Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not support reading date/time fields as text #39

Open
shawndromat opened this issue Aug 17, 2017 · 1 comment
Open

Does not support reading date/time fields as text #39

shawndromat opened this issue Aug 17, 2017 · 1 comment

Comments

@shawndromat
Copy link

Our dates are in a format that is getting incorrectly parsed by the default parsing strategies.

Our date format is y-mmm, e.g. "16-Aug" for month of August, no day, year 2016
Roo/Roo-xls give us a Date object for 2017-08-16 for month of August, day 16, year 2017

sheet.cell(1,1) => #<Date: 2017-08-16 ((2457982j,0s,0n),+0s,2299161j)>

In Roo for .xlsx files, we've been using the #formatted_value method as a workaround. It reformats the date object which essentially gives us the underlying string.

sheet.formatted_cell(1,1) => "16-AUG"

The #formatted_value method is a bit of a hacky workaround but is serving us well enough. But there seems to be no way to get the underlying string representation of a Date, Time, or DateTime field for .xls files in roo-xls.

@NahianAlindo
Copy link

NahianAlindo commented Aug 30, 2024

I had a similar problem where I entered a date like 6/1/2024 in excel spreadsheet in an xlsx file but the date became some big digit 45297 which is actually an offset from 30 Dec 1899. so, you could build a date object or time object if you have an number which represents the object like the following:

Date.new(1899, 12, 30) + offset_number
Time.new(2024,1,1) + offset_number * 86_400

after that you could just use the Date and Time class of Ruby and related methods to do what you want.
N.B: the offset_number can be an integer or a float. and 86400 is just the seconds in a day so, offset_number 0.5 multiplied by 86400 would give you 12pm for a Time object using the offset number from the beginning of some day.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants