mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-26 17:51:13 +08:00
Updated date and time comparison
This commit is contained in:
parent
5055490a23
commit
5345cf0342
8 changed files with 25 additions and 31 deletions
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue