Class: HydraPbcore::Mapper

Inherits:
Solrizer::FieldMapper
  • Object
show all
Defined in:
lib/hydra_pbcore/mapper.rb

Class Method Summary collapse

Class Method Details

.pbcore_date(date, value = String.new) ⇒ Object

We assume that all dates are in ISO 8601 format, but sometimes users may only specify a year or a year and month. This method adds a -01-01 or -01 respectively defaulting to Jan. 1st for dates that are only a year, and the first day of the month for dates that are only a year and a month. NOTE: This only applies to the date as it is stored in solr. The original value as entered by the user is still maintained in the xml.



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/hydra_pbcore/mapper.rb', line 32

def self.pbcore_date(date, value = String.new)
  return date if date.empty?
  if date.match(/^[0-9]{4,4}$/)
    value = date + "-01-01"
  elsif date.match(/^[0-9]{4,4}-[0-9]{2,2}$/)
    value = date + "-01"
  else 
    value = date  
  end
  return DateTime.parse(value).to_time.utc.iso8601
end