Cumulus / Syndic

RSS and Atom feed parsing
MIT License
34 stars 13 forks source link

Fix timezone and sub-second in RFC822 parser. #82

Open paurkedal opened 4 years ago

paurkedal commented 4 years ago

I noticed times from parsed feed comes out in local time without time zone. Looking at the code, this seems unintended. The issue is that passing the time-zone Ptime.to_date_time with both adjust the date and time tuples, as well as passing the time zone offset in the time tuple component, which Ptime.of_date_time uses the latter to adjust the time back to it's original value.

An easy adjustment would substitute 0 for the TZ in between the calls, but I here propose dropping the round-trip all together, as it's easy to substitute the correction into the time span used for composing the time. This also allows us to keep the sub-second precision.

Before:

utop # Syndic__Syndic_date.of_rfc822 "Sun, 19 May 2002 15:21:36 EST Sat";;
- : Ptime.t = 2002-05-19 15:21:36 +00:00

After:

utop # Syndic__Syndic_date.of_rfc822 "Sun, 19 May 2002 15:21:36 EST Sat";;
- : Ptime.t = 2002-05-19 20:21:36 +00:00