Catch date error

This commit is contained in:
Aart van Halteren
2022-09-15 21:55:49 +02:00
parent cef30a9c98
commit e0f5865cd8

View File

@@ -105,11 +105,15 @@ class Entsoe
doc = Nokogiri::XML(URI.open(url))
prices = doc.xpath('.//xmlns:Point').map{|p| parse_point(p)}
# get start_time (in UTC) from XML docment
start_time = DateTime.parse(doc.xpath('.//xmlns:period.timeInterval//xmlns:start').text)
begin
# get start_time (in UTC) from XML docment
start_time = DateTime.parse(doc.xpath('.//xmlns:period.timeInterval//xmlns:start').text)
#returns a hash with keys formatted "yyyy-mm-dd hr" and values price (per kwh)
# <position> tag runs from 1-24. We need hours from 00-23, therefore substracting 1
prices.map{|p| [start_time.advance(hours: (p[0]-1)), p[1]]}.to_h
#returns a hash with keys formatted "yyyy-mm-dd hr" and values price (per kwh)
# <position> tag runs from 1-24. We need hours from 00-23, therefore substracting 1
prices.map{|p| [start_time.advance(hours: (p[0]-1)), p[1]]}.to_h
rescue Date::Error => e
p e.message
end
end
end