Module: Spix::Parser::DateTimeUtilities

Included in:
Feed, FeedEntry
Defined in:
lib/spix_parser/datetime.rb

Instance Method Summary collapse

Instance Method Details

#build_datetime_object(timestamp) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/spix_parser/datetime.rb', line 5

def build_datetime_object(timestamp)
  timestamp = normalize_timestamp(timestamp)

  if Time.can_parse?(timestamp)
    #if the timestamp is a non-date string, it will be Time.mktime("1970").utc
    timestamp = Time.parse(timestamp, Spix::Parser::Config::BASE_TIMESTAMP).utc

    # non-english dates sometimes are parsed to "future" dates by Ruby
    # we also cover the case where the timestamp is Time.mktime("1970").utc as explained above
    if (timestamp > Time.now.utc) || (timestamp == Spix::Parser::Config::BASE_TIMESTAMP)
      timestamp = nil
    end
  else
    timestamp = nil
  end

  timestamp
end