Class: Tabledata::ColumnDefinition::DateTimeProcessor

Inherits:
Object
  • Object
show all
Defined in:
lib/tabledata/column_definition.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ DateTimeProcessor


91
92
# File 'lib/tabledata/column_definition.rb', line 91

def initialize(options)
end

Instance Method Details

#call(value, errors) ⇒ Object


93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/tabledata/column_definition.rb', line 93

def call(value, errors)
  case value
    when DateTime
      processed = value
    when Time
      processed = DateTime.civil(value.year, value.month, value.day, value.hour, value.min, value.sec+value.usec.fdiv(1000000), value.zone)
    when Date
      processed = DateTime.civil(value.year, value.month, value.day)
    when /\A(\d{4})-(\d\d)-(\d\d)(?:[T ](\d\d)(?::(\d\d)(?::(\d\d))?)?)?\z/
      processed = DateTime.civil($1.to_i, $2.to_i, $3.to_i, $4.to_i, $5.to_i, $6.to_i)
    when /\A\s*\z/
      processed = nil
    else
      errors << [:invalid_input, {value: value}]
  end

  if processed
    # validate
  end

  processed
end