app/services/edtf_date_service.rb
# A service for indexing and humanzing EDTF dates
# Used by app/indexers/work_indexer for date_created and
# chronological_coverage.
# (see https://www.loc.gov/standards/datetime/).
#
# For extended examples of different types of dates and
# what they index as, see
# spec/services/edtf_date_service_spec.rb
#
# Based on the edtf gem by Sylvester Keil
# (https://github.com/inukshuk/edtf-ruby)
# and the edtf-humanize gem from Duke Libraries.
# (https://github.com/duke-libraries/edtf-humanize)
A service for indexing and humanzing EDTF dates
Used by app/indexers/work_indexer for date_created and
chronological_coverage.

For extended examples of different types of dates and
what they index as, see
spec/services/edtf_date_service_spec.rb

Based on the edtf gem by Sylvester Keil

and the edtf-humanize gem from Duke Libraries.
A service for indexing and humanzing EDTF dates Used by app / indexers / work_indexer for date_created and chronological_coverage . For extended examples of different types of dates and what they index as see spec / services / edtf_date_service_spec . rb Based on the edtf gem by Sylvester Keil and the edtf - humanize gem from Duke Libraries .
def parse_date(date_string)
    date_string = date_string.gsub('%','~')
    if date_string == "unknown" or date_string == "no date"
      date_string
    elsif date_string.include? "/.." 
      Date.edtf(date_string.split("/").first)
    elsif date_string.include? "../"
      Date.edtf(date_string.split("/").last)
    elsif season_interval?(date_string) or century_interval?(date_string) or decade_interval?(date_string)
      first_date = Date.edtf(date_string.split("/").first)
      last_date = Date.edtf(date_string.split("/").last)
      EDTF::Interval.new(first_date.first, last_date.last)
    elsif Date.edtf(date_string).nil? 
      if date_string.include? "#"
        raise InvalidEdtfDateError.new("Could not parse date: \"#{date_string}.\" Date includes #, please use X or another alternative.")
      else
        raise InvalidEdtfDateError.new("Could not parse date: \"#{date_string}.\" If date is unknown, use \"unknown\" or \"no date\"")
      end
    else
      temp_date = date_string.gsub('/..','').gsub('%','?').gsub(/\/$/,'')
      date = temp_date.include?("/") ? temp_date.gsub(/([0-9]+X+\/)([0-9]+)(X+)/){"#{$1}"+"#{$2.to_i+1}"+"#{$3}"}.gsub("X","u") : temp_date
      if match = date[/\d{3}u/] 
        date.gsub!(match, match.gsub("u","0"))
      end
      Date.edtf(date)
    end
  end
def parse_date ( date_string ) date_string = date_string . gsub ( '%' , '~' ) if date_string == "unknown" or date_string == "no date" date_string elsif date_string . include? "/.." Date . edtf ( date_string . split ( "/" ) . first ) elsif date_string . include? "../" Date . edtf ( date_string . split ( "/" ) . last ) elsif season_interval? ( date_string ) or century_interval? ( date_string ) or decade_interval? ( date_string ) first_date = Date . edtf ( date_string . split ( "/" ) . first ) last_date = Date . edtf ( date_string . split ( "/" ) . last ) EDTF :: Interval . new ( first_date . first , last_date . last ) elsif Date . edtf ( date_string ) . nil? if date_string . include? "#" raise InvalidEdtfDateError . new ( "Could not parse date: \"#{date_string}.\" Date includes #, please use X or another alternative." ) else raise InvalidEdtfDateError . new ( "Could not parse date: \"#{date_string}.\" If date is unknown, use \"unknown\" or \"no date\"" ) end else temp_date = date_string . gsub ( '/..' , '' ) . gsub ( '%' , '?' ) . gsub ( / \/ $ / , '' ) date = temp_date . include? ( "/" ) ? temp_date . gsub ( / ([0-9]+X+ \/ )([0-9]+)(X+) / ) { "#{$1}" + "#{$2.to_i+1}" + "#{$3}" } . gsub ( "X" , "u" ) : temp_date if match = date [ / \d {3}u / ] date . gsub! ( match , match . gsub ( "u" , "0" ) ) end Date . edtf ( date ) end end
A service for indexing and humanzing EDTF dates
Used by app/indexers/work_indexer for date_created and
chronological_coverage.
A service for indexing and humanzing EDTF dates Used by app / indexers / work_indexer for date_created and chronological_coverage .
# This is an open-ended interval such as "1867/.. " # Only index the first date # edtf can't parse season or century intervals, so we create an interval using the first season's # first date and the last season's last date # Invalid date # modify date so that the interval encompasses the years on the last interval date # edtf can't parse single u in year (e.g. 192u), so we replace it
date_string
<not_specific>