Class: DBF::ColumnType::DateTime

Inherits:
Base
  • Object
show all
Defined in:
lib/dbf/column_type.rb

Instance Attribute Summary

Attributes inherited from Base

#decimal, #encoding

Instance Method Summary collapse

Methods inherited from Base

#blank_value, #decode, #initialize, #skip_blank?

Constructor Details

This class inherits a constructor from DBF::ColumnType::Base

Instance Method Details

#type_cast(value) ⇒ Object

Parameters:



122
123
124
125
126
127
128
129
130
# File 'lib/dbf/column_type.rb', line 122

def type_cast(value)
  days, msecs = value.unpack('l2')
  return nil if days.nil? || days.zero?

  secs = (msecs / 1000).to_i
  ::DateTime.jd(days, (secs / 3600).to_i, (secs / 60).to_i % 60, secs % 60).to_time
rescue StandardError
  nil
end