2019-12-06 19:50:19 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class RepositoryTimeRangeValue < RepositoryDateTimeRangeValueBase
|
2020-02-03 22:20:01 +08:00
|
|
|
PRELOAD_INCLUDE = :repository_time_range_value
|
|
|
|
|
2019-12-08 23:53:59 +08:00
|
|
|
def data_changed?(new_data)
|
2019-12-17 20:42:25 +08:00
|
|
|
data = JSON.parse(new_data).symbolize_keys
|
|
|
|
|
|
|
|
st = Time.zone.parse(data[:start_time])
|
|
|
|
et = Time.zone.parse(data[:end_time])
|
2019-12-10 20:39:08 +08:00
|
|
|
st.hour != start_time.hour || et.hour != end_time.hour || st.min != start_time.min || et.min != end_time.min
|
2019-12-08 23:53:59 +08:00
|
|
|
end
|
|
|
|
|
2019-12-10 20:39:08 +08:00
|
|
|
def formatted
|
|
|
|
super(:time)
|
2019-12-08 23:53:59 +08:00
|
|
|
end
|
2019-12-09 20:48:24 +08:00
|
|
|
|
|
|
|
def self.new_with_payload(payload, attributes)
|
2019-12-17 20:42:25 +08:00
|
|
|
data = JSON.parse(payload).symbolize_keys
|
|
|
|
|
2019-12-09 20:48:24 +08:00
|
|
|
value = new(attributes)
|
2019-12-17 20:42:25 +08:00
|
|
|
value.start_time = Time.zone.parse(data[:start_time])
|
|
|
|
value.end_time = Time.zone.parse(data[:end_time])
|
2019-12-09 20:48:24 +08:00
|
|
|
value
|
|
|
|
end
|
2020-01-10 16:29:20 +08:00
|
|
|
|
|
|
|
alias export_formatted formatted
|
2019-12-06 19:50:19 +08:00
|
|
|
end
|