Module: TimeCompact

Defined in:
lib/time_compact.rb,
lib/time_compact/railtie.rb,
lib/time_compact/version.rb

Defined Under Namespace

Classes: Railtie

Constant Summary collapse

VERSION =
'0.3.0'

Instance Method Summary collapse

Instance Method Details

#time_compact(time, now = Time.now) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/time_compact.rb', line 7

def time_compact(time, now = Time.now)
  locale_dir = File.expand_path('../../locale', __FILE__)
  I18n.enforce_available_locales = true
  I18n.load_path += Dir["#{locale_dir}/*.yml"]
  messages = I18n.t('time_compact')

  if time.year == now.year
    if time.month == now.month
      if time.day == now.day
        if time.hour == now.hour
          time.strftime(messages[:same_hour])
        else
          time.strftime(messages[:same_day])
        end
      else
        time.strftime(messages[:same_month])
      end
    else
      time.strftime(messages[:same_year])
    end
  else
    time.strftime(messages[:other])
  end
end