Class: Spreadsheet::Excel::Row

Inherits:
Row
  • Object
show all
Defined in:
lib/roo/excel.rb

Instance Method Summary collapse

Instance Method Details

#_dateObject

#_datetime(data) ⇒ Object

:nodoc:



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/roo/excel.rb', line 15

def _datetime data # :nodoc:
  return data if data.is_a?(DateTime)
  base = @worksheet.date_base
  date = base + data.to_f
  hour = (data % 1) * 24
  min  = (hour % 1) * 60
  sec  = ((min % 1) * 60).round
  min = min.floor
  hour = hour.floor
  if sec > 59
    sec = 0
    min += 1
  end
  if min > 59
    min = 0
    hour += 1
  end
  if hour > 23
    hour = 0
    date += 1
  end
  if LEAP_ERROR > base
    date -= 1
  end
  DateTime.new(date.year, date.month, date.day, hour, min, sec)
end