Module: Incline::Extensions::TimeZoneConverter

Defined in:
lib/incline/extensions/time_zone_converter.rb

Overview

Patches the TimeZoneConverter to call super.

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object

Patches the TimeZoneConverter to call super.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/incline/extensions/time_zone_converter.rb', line 10

def self.included(base)
  base.class_eval do

    undef type_cast_from_user

    def type_cast_from_user(value)
      if value.is_a?(::Array)
        value.map { |v| type_cast_from_user(v) }
      else
        # Convert to time first.
        value = super

        # Then convert the time zone if necessary.
        if value.respond_to?(:in_time_zone)
          begin
            value.in_time_zone
          rescue ArgumentError
            nil
          end
        else
          nil
        end
      end
    end
  end
end