Method: ActiveScaffold::Finder::ClassMethods#format_for_datetime

Defined in:
lib/active_scaffold/finder.rb

#format_for_datetime(column, value) ⇒ Object



254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
# File 'lib/active_scaffold/finder.rb', line 254

def format_for_datetime(column, value)
  parts = Date._parse(value)
  if ActiveScaffold.js_framework == :jquery
    format = I18n.translate "time.formats.#{column.options[:format] || :picker}", :default => ''
  end

  if format.blank?
    time_parts = [[:hour, '%H'], [:min, '%M'], [:sec, '%S']].map do |part, format_part|
      format_part if parts[part].present?
    end.compact
    format = "#{I18n.t('date.formats.default')} #{time_parts.join(':')} #{'%z' if parts[:offset].present?}"
  else
    [[:hour, '%H'], [:min, ':%M'], [:sec, ':%S']].each do |part, f|
      format.gsub!(f, '') if parts[part].blank?
    end
    format += ' %z' if parts[:offset].present? && format !~ /%z/i
  end

  format.gsub!(/.*(?=%H)/, '') if !parts[:year] && !parts[:month] && !parts[:mday]
  [format, parts[:offset]]
end