Skip to content

Commit

Permalink
Merge df6c140 into b6df3c1
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvieed committed May 10, 2022
2 parents b6df3c1 + df6c140 commit 5ea5b34
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
15 changes: 14 additions & 1 deletion app/models/work.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,20 @@ def document_date=(date_as_edtf)
end

def document_date
Date.edtf(self[:document_date])
date = Date.edtf(self[:document_date])

if self[:document_date].nil? # there is no document date
return nil
elsif date.nil? # the document date is invalid
return self[:document_date]
# assign date precision based on length of document_date string (edtf-ruby does not do this automatically)
elsif self[:document_date].length == 7 # YYYY-MM
date.month_precision!
elsif self[:document_date].length == 4 and not self[:document_date].include? "x" # YYYY
date.year_precision!
end

return date.edtf
end

def document_date_is_edtf
Expand Down
2 changes: 1 addition & 1 deletion app/views/work/edit.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
td =f.text_field :location_of_composition, value: @work.location_of_composition
tr
th =f.label :document_date, 'Document Date'
td =f.text_field :document_date, value: @work.document_date
td =f.text_field :document_date, value: @work.document_date, placeholder: 'yyyy-mm-dd'
tr
th =f.label :genre
td =f.text_field :genre, value: @work.genre
Expand Down

0 comments on commit 5ea5b34

Please sign in to comment.