class Embulk::Guess::TimeFormatGuess::GuessPattern

def match(text)

def match(text)
  delimiters = []
  parts = []
  part_options = []
  if dm = (/^#{YMD}(?<rest>.*?)$/.match(text) or /^#{YMD_NODELIM}(?<rest>.*?)$/.match(text))
    date_delim = dm["date_delim"] rescue ""
    parts << :year
    part_options << nil
    delimiters << date_delim
    parts << :month
    part_options << part_heading_option(dm["month"])
    delimiters << date_delim
    parts << :day
    part_options << part_heading_option(dm["day"])
  elsif dm = (/^#{MDY}(?<rest>.*?)$/.match(text) or /^#{MDY_NODELIM}(?<rest>.*?)$/.match(text))
    date_delim = dm["date_delim"] rescue ""
    parts << :month
    part_options << part_heading_option(dm["month"])
    delimiters << date_delim
    parts << :day
    part_options << part_heading_option(dm["day"])
    delimiters << date_delim
    parts << :year
    part_options << nil
  elsif dm = (/^#{DMY}(?<rest>.*?)$/.match(text) or /^#{DMY_NODELIM}(?<rest>.*?)$/.match(text))
    date_delim = dm["date_delim"] rescue ""
    parts << :day
    part_options << part_heading_option(dm["day"])
    delimiters << date_delim
    parts << :month
    part_options << part_heading_option(dm["month"])
    delimiters << date_delim
    parts << :year
    part_options << nil
  else
    date_delim = ""
    return nil
  end
  rest = dm["rest"]
  date_time_delims = /(:? |_|T|\. ?)/
  if tm = (
        /^(?<date_time_delim>#{date_time_delims})#{TIME}(?<rest>.*?)?$/.match(rest) or
        /^(?<date_time_delim>#{date_time_delims})#{TIME_NODELIM}(?<rest>.*?)?$/.match(rest) or
        (date_delim == "" && /^#{TIME_NODELIM}(?<rest>.*?)?$/.match(rest))
      )
    date_time_delim = tm["date_time_delim"] rescue ""
    time_delim = tm["time_delim"] rescue ""
    delimiters << date_time_delim
    parts << :hour
    part_options << part_heading_option(tm["hour"])
    if tm["minute"]
      delimiters << time_delim
      parts << :minute
      part_options << part_heading_option(tm["minute"])
      if tm["second"]
        delimiters << time_delim
        parts << :second
        part_options << part_heading_option(tm["second"])
        if tm["frac"]
          delimiters << tm["frac_delim"]
          parts << :frac
          part_options << tm["frac"].size
        end
      end
    end
    rest = tm["rest"]
  end
  if zm = /^#{ZONE}$/.match(rest)
    delimiters << (zm["zone_space"] || '')
    parts << :zone
    if zm["zone_off"]
      if zm["zone_off"].include?(':')
        part_options << :extended
      else
        part_options << :simple
      end
    else
      part_options << :abb
    end
    return GuessMatch.new(delimiters, parts, part_options)
  elsif rest =~ /^\s*$/
    return GuessMatch.new(delimiters, parts, part_options)
  else
    return nil
  end
end

def part_heading_option(text)

def part_heading_option(text)
  if text[0] == '0'
    :zero
  elsif text[0] == ' '
    :blank
  elsif text.size == 1
    :none
  else
    nil
  end
end