We were displaying dates in two different formats in the same component, leading to strange hacks like manually calling the `call` method or not being able to use `render_inline` in the tests. Since we're going to reuse one of these formats outside the budgets section, we're splitting the component. We're also removing the mentioned hacks.
22 lines
375 B
Ruby
22 lines
375 B
Ruby
class Admin::DurationComponent < ApplicationComponent
|
|
attr_reader :durable
|
|
|
|
def initialize(durable)
|
|
@durable = durable
|
|
end
|
|
|
|
private
|
|
|
|
def dates
|
|
render Admin::DateRangeComponent.new(start_time, end_time)
|
|
end
|
|
|
|
def start_time
|
|
durable.starts_at
|
|
end
|
|
|
|
def end_time
|
|
durable.ends_at - 1.second if durable.ends_at.present?
|
|
end
|
|
end
|