Class: Feedjira::DateTimeUtilities::DateTimePatternParser

Inherits:
Object
  • Object
show all
Defined in:
lib/feedjira/date_time_utilities/date_time_pattern_parser.rb

Constant Summary collapse

JAPANESE_SYMBOLS =

Japanese Symbols are required for strange Date Strings like '水, 31 8 2016 07:37:00 PDT'

%w[      ].freeze
PATTERNS =
["%m/%d/%Y %T %p", "%d %m %Y %T %Z"].freeze

Class Method Summary collapse

Class Method Details

.parse(string) ⇒ Object


11
12
13
14
15
16
17
18
19
20
21
# File 'lib/feedjira/date_time_utilities/date_time_pattern_parser.rb', line 11

def self.parse(string)
  PATTERNS.each do |p|
    datetime = DateTime.strptime(prepare(string), p)
    return datetime
  rescue StandardError => e
    Feedjira.logger.debug("Failed to parse date #{string}")
    Feedjira.logger.debug(e)
    nil
  end
  raise "No pattern matched #{string}"
end