Updated date and time comparison

This commit is contained in:
Urban Rotnik 2019-12-10 13:39:08 +01:00
parent 5055490a23
commit 5345cf0342
8 changed files with 25 additions and 31 deletions

View file

@ -4,11 +4,11 @@ class RepositoryDateRangeValue < RepositoryDateTimeRangeValueBase
def data_changed?(new_data)
st = Time.zone.parse(new_data[:start_time])
et = Time.zone.parse(new_data[:end_time])
formatted != formatted(new_dates: [st, et])
st.to_date != start_time.to_date || et.to_date != end_time.to_date
end
def formatted(new_dates: nil)
super(:full_date, new_dates: new_dates)
def formatted
super(:full_date)
end
def self.new_with_payload(payload, attributes)

View file

@ -4,11 +4,11 @@ class RepositoryDateTimeRangeValue < RepositoryDateTimeRangeValueBase
def data_changed?(new_data)
st = Time.zone.parse(new_data[:start_time])
et = Time.zone.parse(new_data[:end_time])
formatted != formatted(new_dates: [st, et])
st.to_i != start_time.to_i || et.to_i != end_time.to_i
end
def formatted(new_dates: nil)
super(:full_with_comma, new_dates: new_dates)
def formatted
super(:full_with_comma)
end
def self.new_with_payload(payload, attributes)

View file

@ -30,18 +30,10 @@ class RepositoryDateTimeRangeValueBase < ApplicationRecord
private
def formatted(format, new_dates: nil)
if new_dates&.any?
st = new_dates[0]
et = new_dates[1]
else
st = start_time
et = end_time
end
def formatted(format)
[
I18n.l(st, format: format),
I18n.l(et, format: format)
I18n.l(start_time, format: format),
I18n.l(end_time, format: format)
].compact.join(' - ')
end
end

View file

@ -2,11 +2,12 @@
class RepositoryDateTimeValue < RepositoryDateTimeValueBase
def data_changed?(new_data)
formatted != formatted(new_date: new_data)
new_time = Time.zone.parse(new_data)
new_time.to_i != data.to_i
end
def formatted(new_date: nil)
super(:full_with_comma, new_date: new_date)
def formatted
super(:full_with_comma)
end
def self.new_with_payload(payload, attributes)

View file

@ -25,8 +25,7 @@ class RepositoryDateTimeValueBase < ApplicationRecord
private
def formatted(format, new_date: nil)
d = new_date ? Time.zone.parse(new_date) : data
def formatted(format)
I18n.l(d, format: format)
end
end

View file

@ -2,11 +2,12 @@
class RepositoryDateValue < RepositoryDateTimeValueBase
def data_changed?(new_data)
formatted != formatted(new_date: new_data)
new_time = Time.zone.parse(new_data)
new_time.to_date != data.to_date
end
def formatted(new_date: nil)
super(:full_date, new_date: new_date)
def formatted
super(:full_date)
end
def self.new_with_payload(payload, attributes)

View file

@ -4,11 +4,11 @@ class RepositoryTimeRangeValue < RepositoryDateTimeRangeValueBase
def data_changed?(new_data)
st = Time.zone.parse(new_data[:start_time])
et = Time.zone.parse(new_data[:end_time])
formatted != formatted(new_dates: [st, et])
st.hour != start_time.hour || et.hour != end_time.hour || st.min != start_time.min || et.min != end_time.min
end
def formatted(new_dates: nil)
super(:time, new_dates: new_dates)
def formatted
super(:time)
end
def self.new_with_payload(payload, attributes)

View file

@ -2,11 +2,12 @@
class RepositoryTimeValue < RepositoryDateTimeValueBase
def data_changed?(new_data)
formatted != formatted(new_date: new_data)
new_time = Time.zone.parse(new_data)
new_time.min != data.min || new_time.hour != data.hour
end
def formatted(new_date: nil)
super(:time, new_date: new_date)
def formatted
super(:time)
end
def self.new_with_payload(payload, attributes)