Module: DateCasually::Translator::DayOfWeek

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

Class Method Summary collapse

Class Method Details

.translate(date) ⇒ Object

Scopes for translation into day of week



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

def self.translate(date)
  today = Date.today
  case
  when date == today then I18n.t('date.casual.today')
  when (date - today).abs <= 3
    key = today < date ? "date.casual.this_wday_#{date.wday}" : "date.casual.this_past_wday_#{date.wday}"
    I18n.t(key)
  when DateCasually::Calculator.last_week_range.include?(date)
    I18n.t("date.casual.last_wday_#{date.wday}")
  when DateCasually::Calculator.next_week_range.include?(date)
    I18n.t("date.casual.next_wday_#{date.wday}")
  else
    nil
  end
end

.translate_count(date) ⇒ Object

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



23
24
25
26
# File 'lib/date-casually/translator/day_of_week.rb', line 23

def self.translate_count(date)
  key = Date.today < date ? "date.casual.wdays_from_now_#{date.wday}" : "date.casual.wdays_ago_#{date.wday}"
  I18n.t(key, :number => DateCasually::Calculator.number_of_weeks_from_today(date))      
end