Module: DateCasually::Translator::Days

Defined in:
lib/date-casually/translator/days.rb

Class Method Summary collapse

Class Method Details

.translate(date) ⇒ Object

Scopes for translation into days



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/date-casually/translator/days.rb', line 6

def self.translate(date)
  today = Date.today
  case
  when date == today then I18n.t('date.casual.today')
  when date == today + 1 then I18n.t('date.casual.tomorrow')
  when date == (today - 1) then I18n.t('date.casual.yesterday')
  when date == (today + 2) then I18n.t('date.casual.couple_of_days_from_now')
  when date == (today - 2) then I18n.t('date.casual.couple_of_days_ago')
  else nil
  end
end

.translate_count(date) ⇒ Object

Translates into number of days away, e.g. “6 days ago”



19
20
21
22
# File 'lib/date-casually/translator/days.rb', line 19

def self.translate_count(date)
  i18n_key = (date < Date.today) ? 'ago' : 'from_now'
  I18n.t("date.casual.days_#{i18n_key}", :number => (date - Date.today).abs) 
end