Patch to consistently coerce raw datetime value to a float

43 views
Skip to first unread message

bo...@airbladesoftware.com

unread,
Apr 19, 2013, 9:03:53 AM4/19/13
to rubyspr...@googlegroups.com
Hello,

Here's a patch to fix a problem where a cell whose format is set to datetime actually contains a string.

In my case I had a cell with string "823.63" but its format was set to datetime.  The `_datetime` method coerces its argument to a float in `date = base + data.to_f`, but in the very next line it doesn't coerce: `hour = (data % 1) * 24`.  If `data` is a string this will lead to a NoMethodError two lines later when the `round` message is sent to `sec`.

Apologies if this isn't the preferred way of submitting patches.  I looked around but couldn't find an alternative.

diff --git a/lib/spreadsheet/excel/row.rb b/lib/spreadsheet/excel/row.rb
index eadca74..b9b906b 100644
--- a/lib/spreadsheet/excel/row.rb
+++ b/lib/spreadsheet/excel/row.rb
@@ -58,7 +58,7 @@ class Row < Spreadsheet::Row
     return data if data.is_a?(DateTime)
     base = @worksheet.date_base
     date = base + data.to_f
-    hour = (data % 1) * 24
+    hour = (data.to_f % 1) * 24
     min  = (hour % 1) * 60
     sec  = ((min % 1) * 60).round
     min = min.floor

Many thanks,
Andy Stewart

Zeno Davatz

unread,
Apr 19, 2013, 11:46:43 AM4/19/13
to rubyspr...@googlegroups.com
Dear Andy

Thanks for reporting this! I will test this asap!

Best
Zeno
--
You received this message because you are subscribed to the Google Groups "spreadsheet" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyspreadshe...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Zeno Davatz

unread,
Apr 20, 2013, 7:31:14 AM4/20/13
to rubyspr...@googlegroups.com
Dear Andy

I just done a new release: spreadsheet-0.8.4.gem

Next time, clone from

https://github.com/zdavatz/spreadsheet.git

and send me a pull request.

Best
Zeno

Andrew Stewart

unread,
Apr 22, 2013, 4:09:23 AM4/22/13
to rubyspr...@googlegroups.com
On 20 Apr 2013, at 13:31, Zeno Davatz wrote:
> I just done a new release: spreadsheet-0.8.4.gem

Thank you very much for the quick response!

> Next time, clone from
>
> https://github.com/zdavatz/spreadsheet.git
>
> and send me a pull request.

Will do. I didn't realise that the code was on GitHub: there's no mention on the rubyforge page or at http://spreadsheet.ch.

http://spreadsheet.rubyforge.org/

Maybe one or both of those could be updated with a link to GitHub?

Anyway, many thanks for the new release.

Yours,
Andy Stewart

Zeno Davatz

unread,
Apr 22, 2013, 4:35:32 AM4/22/13
to rubyspr...@googlegroups.com
Dear Andy

Thank you for your Mail.

I was neglecting Rubyforge! Ts ts ...

I just updated the documentation now:

http://spreadsheet.rubyforge.org/

Best
Zeno
Reply all
Reply to author
Forward
0 new messages