Sha256: e67b63dd14c39edcbdc64d7393c7911d431f2a594c054d2937f86872cfea5ebb

Contents?: true

Size: 741 Bytes

Versions: 8

Compression:

Stored size: 741 Bytes

Contents

module HyperI18n
  module HelperMethods
    def formatted_date_or_time(date_or_time)
      # If the date_or_time parameter is a String, we must parse it to the correct format.

      return date_or_time unless date_or_time.is_a?(String)

      if date_or_time =~ /^\d+\W\d+\W\d+T?\s?\d+:\d+:\d+/
        Time.parse(date_or_time)
      else
        Date.parse(date_or_time)
      end
    end

    def formatted_format(format)
      # If a string is passed in it will use that as the pattern for formatting, ex:
      #
      # I18n.l(Time.now, format: "%b %d, %Y")
      # => "Aug 20, 2017"
      #
      # If a symbol is passed in it will find that definition from the locales.

      format =~ /%/ ? format : :"#{format}"
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
hyper-i18n-0.99.6 lib/hyper-i18n/helper_methods.rb
hyper-i18n-0.99.5 lib/hyper-i18n/helper_methods.rb
hyper-i18n-0.99.4 lib/hyper-i18n/helper_methods.rb
hyper-i18n-0.99.3 lib/hyper-i18n/helper_methods.rb
hyper-i18n-0.99.2 lib/hyper-i18n/helper_methods.rb
hyper-i18n-0.99.1 lib/hyper-i18n/helper_methods.rb
hyper-i18n-0.99.0 lib/hyper-i18n/helper_methods.rb
hyper-i18n-0.1.1 lib/hyper-i18n/helper_methods.rb