Module: Jekyll::Filters::DateLocal

Defined in:
lib/jekyll/filters/date_local.rb

Instance Method Summary collapse

Instance Method Details

#date_local(input, format) ⇒ String

Translates month and day names. This requires certain values on your _data/LANG.yml

Example usage:

page.date | date_local: ‘%e de %B de %Y’ }

Parameters:

  • (String|Date|Time|DateTime)
  • (String)

Returns:

  • (String)

See Also:

  • Jekyll::Filters::DateLocal.{_data/es{_data/es.yml}


17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/jekyll/filters/date_local.rb', line 17

def date_local(input, format)
  require 'date'

  input = ::Jekyll::Utils.parse_date(input) unless input.respond_to? :mon

  # Return early if we don't need to translate
  return input.strftime(format) unless /%(|\^)[aAbBpP]/ =~ format

  input.strftime translate_localization_format(input, format)
rescue ArgumentError, TypeError, ::Jekyll::Errors::InvalidDateError => e
  Jekyll.logger.warn "#{input} is not a valid date: #{e.message}"
  input
end