Files
nairobi/app/components/admin/budgets/duration_component.rb
taitus b1b2cfa8b1 Add new time format :short_datetime
Improve DurationComponent  for render time without seconds.
I believe that adding the seconds in this component is not necessary.
2021-06-10 17:14:01 +02:00

30 lines
677 B
Ruby

class Admin::Budgets::DurationComponent < ApplicationComponent
attr_reader :durable
def initialize(durable)
@durable = durable
end
def dates
safe_join([formatted_start_date, "-", formatted_end_date], " ")
end
def duration
distance_of_time_in_words(durable.starts_at, durable.ends_at) if durable.starts_at && durable.ends_at
end
private
def formatted_start_date
formatted_date(durable.starts_at) if durable.starts_at.present?
end
def formatted_end_date
formatted_date(durable.ends_at - 1.second) if durable.ends_at.present?
end
def formatted_date(time)
time_tag(time, format: :short_datetime)
end
end