On Mon, Apr 27, 2020 at 2:38 AM Tim Hanson <[email protected]> wrote: > > hi, I've installed and am trying out > > Gregor: a date and time library for Racket > > and find it to be very powerful and useful.
Thanks! > > In my current application (digging through mail headers) I'm wondering > whether there is a way to test whether a given date-time format matches > without using exceptions. (I assume that would generally be more efficient > than catching exceptions.) > [...] > > I thought I'd check here: > - does this seem like a reasonable idea? It does to me. > - is mine an unusual use case and most folks know what format to expect and > the exception approach is fine? Good question. If you're expecting dates/times to come in a variety of formats, I can see why you'd want to try out a few of them. And that is made more difficult by having these functions raise exceptions. So I think it would have been wiser to make these functions behave the way you've indicated. Or maybe partially so...? The exceptions that occur during a parse can come from three (I hope I counted them all) three distinct sources: - Your pattern may be lexically invalid (e.g., `(parse-datetime "2/29/2000" "M/f/y")`.) - Your pattern may fail to match the input (e.g., `(parse-datetime "2/29/2000" "MMM/d/y")`.). - Your pattern may match the input, but the interpretation of the input as a date, datetime, etc. may refer to a date that does not exist in the Gregorian calendar (e.g., `(parse-datetime "2/29/1999" "M/d/y")` or a date-time that does not exist in a local time zone (e.g., a time between 2-3 am during a transition to Daylight Saving Time from Standard Time in the U.S.). I think the first of these would definitely remain an exception. The second is the most obvious candidate for returning #f instead of raising. The third is (to me) the least obvious. > - is there perhaps an elegant way for me to test with a regular expression > first rather than adding this function to Gregor? That would depend on the particular formats you're expecting. > > Cheers, > > Tim -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/CAKfDxxzFVQ43L3%3D_61VGTEuoVn-7rZvG5YmHtRO-sw2wM4Xp8A%40mail.gmail.com.

