hoodie / icalendar-rs

📆 icalendar library, in Rust of course - for fun
Apache License 2.0
125 stars 33 forks source link

Convert `icalendar::CalendarDateTime::WithTimezone` to `chrono::DateTime` #49

Open WhyNotHugo opened 2 years ago

WhyNotHugo commented 2 years ago

I'd like to convert a icalendar::CalendarDateTime::WithTimezone to a chrono::DateTime.

I don't think that a chrono::offset::TimeZone can be created with the TZ data inside an icalendar event. This TZ data is often missing info too -- usually transitions relevant to the date encoded are included, but not other unrelated transitions or exceptions.

It might be simpler (or less error prone) to have just a helper method that converts the time to chrono::DateTime<UTC>.

WhyNotHugo commented 2 years ago

Another good approach is to parse VTIMEZONE into some special type first (e.g.: VTimeZone).

And then some helper function to convert: (icalendar::CalendarDateTime::WithTimezone, VTimeZone) -> chrono::DateTime

WhyNotHugo commented 2 years ago

Ok, after re-reading the spec and looking closely at chrono's API, I think the best thing here is to implement a VTimeZone type, which implements chrono::offset::TimeZone. VTimeZone should also impl TryFrom<icalendar::parser::Component>.

Props of value-type UTC-OFFSET can themselves be mapped to chrono::offset::Offset.