class Playbook::PbTimestamp::Timestamp

def classname

def classname
  generate_classname("pb_timestamp_kit", variant_class, align)
end

def datetime_or_text

def datetime_or_text
  timestamp ? format_datetime_string : text
end

def format_date_string

def format_date_string
  "#{pb_date_time.to_month_downcase} #{pb_date_time.to_unpadded_day}#{format_year_string}"
end

def format_datetime_string

def format_datetime_string
  "#{format_date_string} · #{format_time_string}".html_safe
end

def format_elapsed_string

def format_elapsed_string
  user_string = show_user ? " by #{text}" : ""
  datetime_string = " #{pb_time_ago(pb_date_time.convert_to_timestamp)} ago"
  datetime_string[1] = hide_updated ? datetime_string[1].upcase : datetime_string[1]
  updated_string = hide_updated ? "" : "Last updated"
  "#{updated_string}#{user_string}#{datetime_string}"
end

def format_time_string

def format_time_string
  "#{pb_date_time.to_hour}:#{pb_date_time.to_minutes}#{pb_date_time.to_meridian} #{format_timezone_string}".strip
end

def format_timezone_string

def format_timezone_string
  timezone && show_timezone ? pb_date_time.to_timezone.to_s : ""
end

def format_updated_string

def format_updated_string
  user_string = show_user ? " by #{text}" : ""
  datetime_string = " on #{format_date_string} at #{format_time_string}"
  "Last updated#{user_string}#{datetime_string}"
end

def format_year_string

def format_year_string
  pb_date_time.to_year != DateTime.now.year.to_s ? ", #{pb_date_time.to_year}" : ""
end

def pb_date_time

def pb_date_time
  Playbook::PbKit::PbDateTime.new(timestamp, timezone)
end

def pb_time_ago(value)

def pb_time_ago(value)
  time_ago = DateTime.now.to_i - value.to_i
  case time_ago
  when (0...SECS_FORTY_FIVE)
    "a few seconds"
  when (SECS_FORTY_FIVE...SECS_PER_MIN)
    "a minute"
  when (SECS_PER_MIN...SECS_PER_HOUR)
    time = time_ago / SECS_PER_MIN
    time == 1 ? "a minute" : "#{time_ago / SECS_PER_MIN} minutes"
  when (SECS_PER_HOUR...SECS_PER_DAY)
    time = time_ago / SECS_PER_HOUR
    time == 1 ? "an hour" : "#{time_ago / SECS_PER_HOUR} hours"
  when (SECS_PER_DAY...SECS_PER_WEEK)
    time = time_ago / SECS_PER_DAY
    time == 1 ? "a day" : "#{time_ago / SECS_PER_DAY} days"
  when (SECS_PER_WEEK...SECS_PER_26)
    time = time_ago / SECS_PER_WEEK
    time == 1 ? "a week" : "#{time_ago / SECS_PER_WEEK} weeks"
  when (SECS_PER_26...SECS_PER_MONTH)
    "a month"
  when (SECS_PER_MONTH...SECS_PER_320)
    time = time_ago / SECS_PER_MONTH
    time == 1 ? "a month" : "#{time_ago / SECS_PER_MONTH} months"
  when (SECS_PER_320...SECS_PER_YEAR)
    "a year"
  when (SECS_PER_YEAR...SECS_PER_CENT)
    time = time_ago / SECS_PER_YEAR
    time == 1 ? "a year" : "#{time_ago / SECS_PER_YEAR} years"
  end
end

def timestamp_text

def timestamp_text
  case variant
  when "updated"
    format_updated_string
  when "elapsed"
    format_elapsed_string
  else
    show_date ? datetime_or_text : format_time_string
  end
end

def variant_class

def variant_class
  case variant
  when "updated"
    "updated"
  when "elapsed"
    "elapsed"
  end
end