Sha256: 14207d09ff2a4a8c037a1538fa245c27a857f9ba1d5b7674405a973a281faf51
Contents?: true
Size: 1.3 KB
Versions: 5
Compression:
Stored size: 1.3 KB
Contents
module Locomotive module Liquid module Filters module Date 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 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 alias :format_date :localized_date private def to_time(input) case input when Date then input.to_time when String then Time.parse(input) else input end end end ::Liquid::Template.register_filter(Date) end end end
Version data entries
5 entries across 5 versions & 1 rubygems