Class: Axlsx::DateTimeConverter
- Inherits:
-
Object
- Object
- Axlsx::DateTimeConverter
- Defined in:
- lib/axlsx/workbook/worksheet/date_time_converter.rb
Overview
The DateTimeConverter class converts both data and time types to their apprpriate excel serializations
Class Method Summary collapse
-
.date_to_serial(date) ⇒ Numeric
The date_to_serial method converts Date objects to the equivelant excel serialized forms.
-
.time_to_serial(time) ⇒ Numeric
The time_to_serial methond converts a Time object its excel serialized form.
Class Method Details
.date_to_serial(date) ⇒ Numeric
The date_to_serial method converts Date objects to the equivelant excel serialized forms
11 12 13 14 |
# File 'lib/axlsx/workbook/worksheet/date_time_converter.rb', line 11 def self.date_to_serial(date) epoch = Axlsx::Workbook::date1904 ? Date.new(1904) : Date.new(1899, 12, 30) (date-epoch).to_f end |
.time_to_serial(time) ⇒ Numeric
The time_to_serial methond converts a Time object its excel serialized form.
19 20 21 22 23 24 25 26 27 |
# File 'lib/axlsx/workbook/worksheet/date_time_converter.rb', line 19 def self.time_to_serial(time) # Using hardcoded offsets here as some operating systems will not except # 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 epoch = Axlsx::Workbook::date1904 ? epoch1904 : epoch1900 (time.to_f - epoch)/seconds_per_day end |