Sha256: ec8b7bb68ba1bb4a03a0f9e963a8f9da43b5a67cc98b281b58a7c12a0428fbe7

Contents?: true

Size: 533 Bytes

Versions: 4

Compression:

Stored size: 533 Bytes

Contents

class Date
  ##
  # Fuzzy-formats the date. If the date is yesterday, today or tomorrow, a
  # simpler date will be given.
  #
  # @return [String]
  #
  # @example Today.
  #   Date.today.fuzzy # => "Today"
  #
  # @example Some time ago.
  #   (Date.today - 7).fuzzy # => "Wednesday 29th July"
  #
  def fuzzy
    today = Date.today

    case self
      when today     then 'Today'
      when today - 1 then 'Yesterday'
      when today + 1 then 'Tomorrow'
      else                 to_ordinalized_s(:date_only)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
antw-kin-0.3.2 lib/kin/core_ext/date.rb
antw-kin-0.3.3 lib/kin/core_ext/date.rb
antw-kin-0.4.0 lib/kin/core_ext/date.rb
antw-kin-0.4.1 lib/kin/core_ext/date.rb