2019-12-06 19:50:19 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class RepositoryDateValue < RepositoryDateTimeValueBase
|
2019-12-08 23:53:59 +08:00
|
|
|
def data_changed?(new_data)
|
2019-12-10 20:39:08 +08:00
|
|
|
new_time = Time.zone.parse(new_data)
|
|
|
|
new_time.to_date != data.to_date
|
2019-12-08 23:53:59 +08:00
|
|
|
end
|
|
|
|
|
2019-12-10 20:39:08 +08:00
|
|
|
def formatted
|
|
|
|
super(:full_date)
|
2019-12-08 23:53:59 +08:00
|
|
|
end
|
2019-12-09 20:48:24 +08:00
|
|
|
|
|
|
|
def self.new_with_payload(payload, attributes)
|
|
|
|
value = new(attributes)
|
|
|
|
value.data = Time.zone.parse(payload)
|
|
|
|
value
|
|
|
|
end
|
2020-01-10 16:29:20 +08:00
|
|
|
|
2020-03-18 04:20:50 +08:00
|
|
|
def self.import_from_text(text, attributes, options = {})
|
2020-03-18 16:53:47 +08:00
|
|
|
date_format = (options.dig(:user, :settings, :date_format) || Constants::DEFAULT_DATE_FORMAT).gsub(/%-/, '%')
|
2020-03-18 04:20:50 +08:00
|
|
|
new(attributes.merge(data: DateTime.strptime(text, date_format)))
|
|
|
|
rescue ArgumentError
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
2020-01-10 16:29:20 +08:00
|
|
|
alias export_formatted formatted
|
2019-12-06 19:50:19 +08:00
|
|
|
end
|