summaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
authorRandy Morgan <[email protected]>2012-03-02 22:01:33 -0800
committerRandy Morgan <[email protected]>2012-03-02 22:01:33 -0800
commit76ec0a195cdb64928f8e83a7e1620f01dd22921f (patch)
treecd4e3c831f5037c62f2e33d0134a223ad5c1f423 /lib
parentb169cc9d067fb8c195d452768ef4d70414bc25c1 (diff)
parentca7248353d295c74f3dff7e8e003044849c026e7 (diff)
downloadcaxlsx-76ec0a195cdb64928f8e83a7e1620f01dd22921f.tar.gz
caxlsx-76ec0a195cdb64928f8e83a7e1620f01dd22921f.zip
Merge pull request #41 from jurriaan/1904-date-fix
Default to 1900 date system
Diffstat (limited to 'lib')
-rw-r--r--lib/axlsx/workbook/workbook.rb12
-rw-r--r--lib/axlsx/workbook/worksheet/date_time_converter.rb14
2 files changed, 9 insertions, 17 deletions
diff --git a/lib/axlsx/workbook/workbook.rb b/lib/axlsx/workbook/workbook.rb
index b3b10fac..cbb85349 100644
--- a/lib/axlsx/workbook/workbook.rb
+++ b/lib/axlsx/workbook/workbook.rb
@@ -99,25 +99,17 @@ require 'axlsx/workbook/shared_strings_table.rb'
# Creates a new Workbook
# The recomended way to work with workbooks is via Package#workbook
- # @option options [Boolean] date1904. If this is not specified, we try to determine if the platform is bsd/darwin and set date1904 to true automatically.
+ # @option options [Boolean] date1904. If this is not specified, date1904 is set to false. Office 2011 for Mac defaults to false.
def initialize(options={})
@styles = Styles.new
@worksheets = SimpleTypedList.new Worksheet
@drawings = SimpleTypedList.new Drawing
@charts = SimpleTypedList.new Chart
@images = SimpleTypedList.new Pic
- self.date1904= options[:date1904].nil? ? is_bsd? : options[:date1904]
+ self.date1904= !options[:date1904].nil? && options[:date1904]
yield self if block_given?
end
- # Uses RUBY_PLATFORM constant to determine if the OS is freebsd or darwin
- # based on this value we attempt to set date1904.
- # @return [Boolean]
- def is_bsd?
- platform = RUBY_PLATFORM.downcase
- platform.include?('freebsd') || platform.include?('darwin')
- end
-
# Instance level access to the class variable 1904
# @return [Boolean]
def date1904() @@date1904; end
diff --git a/lib/axlsx/workbook/worksheet/date_time_converter.rb b/lib/axlsx/workbook/worksheet/date_time_converter.rb
index 5a572781..d2d9a014 100644
--- a/lib/axlsx/workbook/worksheet/date_time_converter.rb
+++ b/lib/axlsx/workbook/worksheet/date_time_converter.rb
@@ -9,8 +9,8 @@ module Axlsx
# @param [Date] date the date to be serialized
# @return [Numeric]
def self.date_to_serial(date)
- epoc = Axlsx::Workbook::date1904 ? Date.new(1904) : Date.new(1899, 12, 30)
- (date-epoc).to_f
+ epoch = Axlsx::Workbook::date1904 ? Date.new(1904) : Date.new(1899, 12, 30)
+ (date-epoch).to_f
end
# The time_to_serial methond converts a Time object its excel serialized form.
@@ -18,12 +18,12 @@ module Axlsx
# @return [Numeric]
def self.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
+ # a 'negative' offset from the ruby epoch.
+ epoch1900 = -2209161600 # Time.utc(1899, 12, 30).to_i
+ epoch1904 = -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
+ epoch = Axlsx::Workbook::date1904 ? epoch1904 : epoch1900
+ (time.to_f - epoch)/seconds_per_day
end
end
end