hoodie / icalendar-rs

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

Helper to convert `ParseString` into `DatePerhapsTime` #44

Closed WhyNotHugo closed 2 years ago

WhyNotHugo commented 2 years ago

Is there some helper or shortcut to convert a ParseString into an DatePerhapsTime.

I basically have a bunch of these:

ParseString("20220624T140000Z")
ParseString("20220716T141500Z")
ParseString("20220711T163000Z")
ParseString("20220714T163000Z")

There's no docs for ParseString, it's not being generated, apparently. Is this deliberate?

hoodie commented 2 years ago

indirectly, you can create a DatePerhapsTime from a CalendarDateTime from a NaiveDateTime from a &str I think but we can add another From impl for this perhaps

WhyNotHugo commented 2 years ago

This is not a naive date time tho, it's UTC.

My examples weren't the best tho; this field MAY be a CalendarDateTime or a NaiveDate. It may specify a timezone which is defined separately, so for DatePerhapsTime.DateTime, the CalendarDateTime may be any of the three enum variants. There's quite a few branches, though the converted type should always be Result<DatePerhapsTime>.

If you think that writing a From impl is the right approach, I can give it a shot.

WhyNotHugo commented 2 years ago

Related: I don't quite understand why ParseString doesn't show up on the docs. Even adding /// A description and running cargo docs --features parser, it still won't show up. Is it intentionally omitted?

Never mind, it was simply not exposed. See #45.

WhyNotHugo commented 2 years ago

Actually, this needs to be TryFrom, not From. I'll have a PR soonish.