Sha256: 8236179ee2f026f9f28c269b469062577ee621da7b562c64de08ec194a64eed7
Contents?: true
Size: 1007 Bytes
Versions: 5
Compression:
Stored size: 1007 Bytes
Contents
module Avo module Fields class DateTimeField < DateField attr_reader :format attr_reader :time_24hr attr_reader :timezone def initialize(name, **args, &block) super(name, **args, &block) @partial_name = 'date-time-field' @picker_format = args[:picker_format].present? ? args[:picker_format] : 'Y-m-d H:i:S' @time_24hr = args[:time_24hr].present? ? args[:time_24hr] : false @timezone = args[:timezone].present? ? args[:timezone] : Rails.application.config.time_zone end def formatted_value return nil if value.nil? if @format.is_a?(Symbol) value.to_time.in_time_zone(timezone).to_s(@format) else value.to_time.in_time_zone(timezone).strftime(@format) end end def fill_field(model, key, value) return model if value.blank? model[id] = value.to_time.in_time_zone(Rails.application.config.time_zone) model end end end end
Version data entries
5 entries across 5 versions & 1 rubygems