Class: MetalArchives::Parsers::Date

Inherits:
Base
  • Object
show all
Defined in:
lib/metal_archives/parsers/date.rb

Overview

Date parser

Class Method Summary collapse

Class Method Details

.parse(input) ⇒ Object

Parse a date

Returns Date



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/metal_archives/parsers/date.rb', line 14

def self.parse(input)
  ::Date.parse(input)
rescue ::Date::Error
  components = input
    .split("-")
    .map(&:to_i)
    .reject(&:zero?)
    .compact

  return if components.empty?

  ::Date.new(*components)
rescue TypeError
  nil
end