Module: Liquid::StandardFilters

Defined in:
lib/zwite/liquid/ext/date.rb

Instance Method Summary collapse

Instance Method Details

#date(input, format) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/zwite/liquid/ext/date.rb', line 5

def date(input, format)
  if format.to_s.empty?
    return input.to_s
  end

  if ((input.is_a?(String) && !/^\d+$/.match(input.to_s).nil?) || input.is_a?(Integer)) && input.to_i > 0
    input = Time.at(input.to_i)
  end

  date = input.is_a?(String) ? Time.parse(input) : input
  date = date.to_datetime
  
  return Zwite::DateFormat::Formatter.new(date).format(format)
  
rescue => e
  input
end