From ab22ea94b1dde188095581b86df94ecdd91a82da Mon Sep 17 00:00:00 2001 From: Randy Morgan Date: Sat, 10 Dec 2011 12:59:35 +0900 Subject: changing time value storage to retain the value as a Time object until serialization. --- lib/axlsx/workbook/worksheet/cell.rb | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/axlsx/workbook/worksheet/cell.rb b/lib/axlsx/workbook/worksheet/cell.rb index 16608a8f..7e043438 100644 --- a/lib/axlsx/workbook/worksheet/cell.rb +++ b/lib/axlsx/workbook/worksheet/cell.rb @@ -278,6 +278,14 @@ module Axlsx } } end + elsif @type == :time + # Using hardcoded offsets here as some operating systems will not except a 'negative' offset from the ruby epoc. + # (1970) + epoc1900 = -2209021200 #Time.local(1900, 1, 1) + epoc1904 = -2082877200 #Time.local(1904, 1, 1) + epoc = Workbook.date1904 ? epoc1904 : epoc1900 + v = ((@value.localtime.to_f - epoc) /60.0/60.0/24.0).to_f + xml.c(:r => r, :s => style) { xml.v v } else xml.c(:r => r, :s => style) { xml.v value } end @@ -327,15 +335,8 @@ module Axlsx # @see Axlsx#date1904 def cast_value(v) if (@type == :time && v.is_a?(Time)) || (@type == :time && v.respond_to?(:to_time)) - v = v.respond_to?(:to_time) ? v.to_time : v self.style = STYLE_DATE if self.style == 0 - # Using hardcoded offsets here as some operating systems will not except a 'negative' offset from the ruby epoc. - # (1970) - epoc1900 = -2209021200 #Time.local(1900, 1, 1) - epoc1904 = -2082877200 #Time.local(1904, 1, 1) - epoc = Workbook.date1904 ? epoc1904 : epoc1900 - v = ((v.localtime.to_f - epoc) /60.0/60.0/24.0).to_f - ((v * 10**11).round.to_f / 10**11) + v.respond_to?(:to_time) ? v.to_time : v elsif @type == :float v.to_f elsif @type == :integer -- cgit v1.2.3