diff --git a/app/models/metadata_date.rb b/app/models/metadata_date.rb index 9e655d4c..cdde77ce 100644 --- a/app/models/metadata_date.rb +++ b/app/models/metadata_date.rb @@ -1,8 +1,25 @@ # frozen_string_literal: true class MetadataDate < MetadataTemplate + # La fecha de hoy si no hay nada + # + # @return [Date,nil] def default_value - Date.today + case (dv = super) + when String + if dv.present? + begin + Date.parse(dv) + rescue Date::Error => e + ExceptionNotifier.notify_exception(e, data: { site: site.name, post: post.id, name:, type: }) + nil + end + else + nil + end + else + Date.today + end end # Devuelve una fecha, si no hay ninguna es la fecha de hoy. diff --git a/app/views/posts/attribute_ro/_date.haml b/app/views/posts/attribute_ro/_date.haml index cf8ea8ac..d7e275c7 100644 --- a/app/views/posts/attribute_ro/_date.haml +++ b/app/views/posts/attribute_ro/_date.haml @@ -1,3 +1,3 @@ %tr{ id: attribute } %th= post_label_t(attribute, post: post) - %td{ dir: dir, lang: locale }= l metadata.value.to_date + %td{ dir: dir, lang: locale }= l metadata.value diff --git a/app/views/posts/attributes/_date.haml b/app/views/posts/attributes/_date.haml index 1347c59c..f875c53e 100644 --- a/app/views/posts/attributes/_date.haml +++ b/app/views/posts/attributes/_date.haml @@ -1,6 +1,6 @@ .form-group = label_tag "#{base}_#{attribute}", post_label_t(attribute, post: post) - = date_field base, attribute, value: metadata.value.to_date.strftime('%F'), + = date_field base, attribute, value: metadata.value&.strftime('%F'), **field_options(attribute, metadata), pattern: '\d{4}-\d{2}-\d{2}', data: { 'pattern-mismatch': t('metadata.date.invalid_format') } = render 'posts/attribute_feedback',