summaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
authorRandy Morgan <[email protected]>2012-02-23 09:44:33 +0900
committerRandy Morgan <[email protected]>2012-02-23 09:44:33 +0900
commit65ec495117d22df16ef1c3fc94bdcfe0f2d32d30 (patch)
tree8a1828293e96b0e7dc3b2d46cc851e666aa2badb /lib
parente511a47af99813c4b80f5f2dd19507f24a8d6a65 (diff)
downloadcaxlsx-65ec495117d22df16ef1c3fc94bdcfe0f2d32d30.tar.gz
caxlsx-65ec495117d22df16ef1c3fc94bdcfe0f2d32d30.zip
renaming for clarity, a bit of docs and some patches to spec for AWSOME date/time converter as negative date/time does not parse in some environments under 1.8.7
Diffstat (limited to 'lib')
-rw-r--r--lib/axlsx/workbook/workbook.rb2
-rw-r--r--lib/axlsx/workbook/worksheet/converter.rb21
-rw-r--r--lib/axlsx/workbook/worksheet/date_time_converter.rb25
3 files changed, 26 insertions, 22 deletions
diff --git a/lib/axlsx/workbook/workbook.rb b/lib/axlsx/workbook/workbook.rb
index c19c3521..8a6eb629 100644
--- a/lib/axlsx/workbook/workbook.rb
+++ b/lib/axlsx/workbook/workbook.rb
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
module Axlsx
-require 'axlsx/workbook/worksheet/converter.rb'
+require 'axlsx/workbook/worksheet/date_time_converter.rb'
require 'axlsx/workbook/worksheet/cell.rb'
require 'axlsx/workbook/worksheet/row.rb'
require 'axlsx/workbook/worksheet/worksheet.rb'
diff --git a/lib/axlsx/workbook/worksheet/converter.rb b/lib/axlsx/workbook/worksheet/converter.rb
deleted file mode 100644
index 8df08f34..00000000
--- a/lib/axlsx/workbook/worksheet/converter.rb
+++ /dev/null
@@ -1,21 +0,0 @@
-# encoding: UTF-8
-require "date"
-
-module Axlsx
- class Converter
- def date_to_serial(date, date1904=false)
- epoc = date1904 ? Date.new(1904) : Date.new(1899, 12, 30)
- (date-epoc).to_f
- end
-
- def time_to_serial(time, date1904=false)
- # Using hardcoded offsets here as some operating systems will not except
- # a 'negative' offset from the ruby epoc.
- epoc1900 = -2209161600 # Time.utc(1899, 12, 30).to_i
- epoc1904 = -2082844800 # Time.utc(1904, 1, 1).to_i
- seconds_per_day = 86400 # 60*60*24
- epoc = date1904 ? epoc1904 : epoc1900
- (time.to_f - epoc)/seconds_per_day
- end
- end
-end
diff --git a/lib/axlsx/workbook/worksheet/date_time_converter.rb b/lib/axlsx/workbook/worksheet/date_time_converter.rb
new file mode 100644
index 00000000..ee6d4a8a
--- /dev/null
+++ b/lib/axlsx/workbook/worksheet/date_time_converter.rb
@@ -0,0 +1,25 @@
+# encoding: UTF-8
+require "date"
+
+module Axlsx
+ # The DateTimeConverter class converts both data and time types to their apprpriate excel serializations
+ class DateTimeConverter
+
+ # The date_to_serial method converts dates to their excel serialized forms
+ # @param [Date] date the date to be serialized
+ def date_to_serial(date)
+ epoc = Axlsx::Workbook::date1904 ? Date.new(1904) : Date.new(1899, 12, 30)
+ (date-epoc).to_f
+ end
+
+ def time_to_serial(time)
+ # Using hardcoded offsets here as some operating systems will not except
+ # a 'negative' offset from the ruby epoc.
+ epoc1900 = -2209161600 # Time.utc(1899, 12, 30).to_i
+ epoc1904 = -2082844800 # Time.utc(1904, 1, 1).to_i
+ seconds_per_day = 86400 # 60*60*24
+ epoc = Axlsx::Workbook::date1904 ? epoc1904 : epoc1900
+ (time.to_f - epoc)/seconds_per_day
+ end
+ end
+end