Module: Feedjira::DateTimeUtilities

Included in:
FeedEntryUtilities
Defined in:
lib/feedjira/date_time_utilities.rb,
lib/feedjira/date_time_utilities/date_time_epoch_parser.rb,
lib/feedjira/date_time_utilities/date_time_pattern_parser.rb,
lib/feedjira/date_time_utilities/date_time_language_parser.rb

Defined Under Namespace

Classes: DateTimeEpochParser, DateTimeLanguageParser, DateTimePatternParser

Constant Summary collapse

DATE_PARSERS =

This is our date parsing heuristic. Date Parsers are attempted in order.

[
  DateTimePatternParser,
  DateTimeLanguageParser,
  DateTimeEpochParser,
  DateTime
].freeze

Instance Method Summary collapse

Instance Method Details

#parse_datetime(string) ⇒ Object

Parse the given string starting with the most common parser (default ruby) and going over all other available parsers


16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/feedjira/date_time_utilities.rb', line 16

def parse_datetime(string)
  res = DATE_PARSERS.detect do |parser|
    return parser.parse(string).feed_utils_to_gm_time
  rescue StandardError => e
    Feedjira.logger.debug { "Failed to parse date #{string}" }
    Feedjira.logger.debug(e)
    nil
  end

  Feedjira.logger.warn { "Failed to parse date #{string}" } if res.nil?

  res
end