Module: Jekyll::Timeago

Defined in:
lib/jekyll/timeago.rb,
lib/jekyll/timeago/version.rb

Constant Summary collapse

DAYS_PER =
{
  :days => 1,
  :weeks => 7,
  :months => 31,
  :years => 365,
}
MAX_DEPTH_LEVEL =

Max level of detail years > months > weeks > days 1 year and 7 months and 2 weeks and 6 days

4
DEFAULT_DEPTH_LEVEL =

Default level of detail 1 month and 5 days, 3 weeks and 2 days, 2 years and 6 months

2
VERSION =
"0.4.0"

Instance Method Summary collapse

Instance Method Details

#timeago(input, depth = DEFAULT_DEPTH_LEVEL) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/jekyll/timeago.rb', line 22

def timeago(input, depth = DEFAULT_DEPTH_LEVEL)
  unless depth_allowed?(depth)
    raise "Invalid depth level: #{depth.inspect}"
  end

  unless input.is_a?(Date) || input.is_a?(Time)
    raise "Invalid input type: #{input.inspect}"
  end

  days_passed = (Date.today - Date.parse(input.to_s)).to_i
  time_ago_to_now(days_passed, depth)
end