Sha256: e4b56c91ea015d86156d690ab8b6f910ab666081c388984557c730ff76b1a7a4
Contents?: true
Size: 820 Bytes
Versions: 1
Compression:
Stored size: 820 Bytes
Contents
require "format_time/version" module FormatTime include ActionView::Helpers::DateHelper class Error < StandardError; end # Your code goes here... def format_relative_time(time) return '-' if time.nil? distance_of_time_in_words_to_now(time, include_seconds: true) end def format_absolute_time(time) return '-' if time.nil? Time.current.year == time.year ? in_year(time) : previous_year(time) end private def in_year(time) if time.today? format_relative_time(time) elsif time.to_date == Date.yesterday I18n.l(time, format: :yesterday) elsif time.to_date.cweek == Date.current.cweek I18n.l(time, format: :in_week) else I18n.l(time, format: :normal) end end def previous_year(time) I18n.l(time, format: :previous_year) end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
format_time-0.1.2 | lib/format_time.rb |