Class: CocinaDisplay::Dates::MMDDYYFormat

Inherits:
ExtractorDateFormat show all
Defined in:
lib/cocina_display/dates/date.rb

Overview

Extractor for MM/DD/YY-formatted dates

Constant Summary collapse

REGEX =
/(?<month>\d{1,2})\/(?<day>\d{1,2})\/(?<year>\d{2})/

Constants inherited from Date

Date::BCE_CHAR_SORT_MAP, Date::UNPARSABLE_VALUES

Instance Attribute Summary

Attributes inherited from Date

#cocina, #date, #type

Class Method Summary collapse

Methods inherited from ExtractorDateFormat

supports?

Methods inherited from Date

#<=>, #approximate?, #as_range, #base_value, #decoded_value, #encoding, #encoding?, #end?, format_date, from_cocina, #inferred?, #initialize, #parsable?, parse_date, #parsed_date?, #precision, #primary?, #qualified?, #qualified_value, #qualifier, #questionable?, #sort_key, #start?, #to_a, #value

Constructor Details

This class inherits a constructor from CocinaDisplay::Dates::Date

Class Method Details

.munge_to_yyyy(year) ⇒ Object

For two-digit year, if it would be in the future, more likely to just be the previous century. 12/1/99 -> 1999



540
541
542
543
544
545
546
# File 'lib/cocina_display/dates/date.rb', line 540

def self.munge_to_yyyy(year)
  if year.to_i > (::Date.current.year - 2000)
    "19#{year}"
  else
    "20#{year}"
  end
end

.normalize_to_edtf(value) ⇒ Object



532
533
534
535
536
# File 'lib/cocina_display/dates/date.rb', line 532

def self.normalize_to_edtf(value)
  matches = value.match(self::REGEX)
  year = munge_to_yyyy(matches[:year])
  "#{year}-#{matches[:month].rjust(2, "0")}-#{matches[:day].rjust(2, "0")}"
end