Module: Locomotive::Liquid::Filters::Date

Defined in:
lib/locomotive/liquid/filters/date.rb

Instance Method Summary collapse

Instance Method Details

#distance_of_time_in_words(input, from_time = Time.now) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/locomotive/liquid/filters/date.rb', line 6

def distance_of_time_in_words(input, from_time = Time.now)
  # make sure we deals with instances of Time
  input     = to_time(input)
  from_time = to_time(from_time)

  ::ActionController::Base.helpers.distance_of_time_in_words(input, from_time)
end

#localized_date(input, *args) ⇒ Object Also known as: format_date



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/locomotive/liquid/filters/date.rb', line 14

def localized_date(input, *args)
  return '' if input.blank?

  format, locale = args

  locale ||= I18n.locale
  format ||= I18n.t('date.formats.default', :locale => locale)

  if input.is_a?(String)
    begin
      fragments = ::Date._strptime(input, format)
      input = ::Date.new(fragments[:year], fragments[:mon], fragments[:mday])
    rescue
      input = Time.parse(input)
    end
  end

  return input.to_s unless input.respond_to?(:strftime)

  I18n.l input, :format => format, :locale => locale
end