Files
grecia/app/components/admin/budgets/duration_component.rb
Javi Martín 93a7d28a82 Fix crash with budgets with no published phases
In this case, the duration of the budget cannot be determined, and the
application was crashing when trying to do so.

Now we're just returning `nil` as duration.
2021-06-02 18:00:17 +02:00

30 lines
671 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: :datetime)
end
end