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.

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've forked https://github.com/97jaz/gregor

and successfully added a couple of tests that work to tests/parse.rkt:

     (test-suite
      "some datetime particulars"
      (check-equal?
       (parse-datetime "2015-03-15T02:02:02-04:00" "yyyy-MM-dd'T'HH:mm:ssxxx") 
(datetime 2015 3 15 2 2 2))

      (parameterize ([current-locale "en"])
        (check-equal?
         (parse-datetime "21 Jun 2015 15:45:40" "dd MMM yyyy HH:mm:ss") 
(datetime 2015 6 21 15 45 40)))

      (check-exn
       exn:gregor:parse?
       (lambda ()
         (parse-datetime  "21 Jun 2015 15:45:40 -0000" 
"yyyy-MM-dd'T'HH:mm:ssxxx")))
    )


I'd like to add something along these lines:

      (check-equal?
       (parsable-as-datetime? "2015-03-15T02:02:02-04:00" 
"yyyy-MM-dd'T'HH:mm:ssxxx")
       #t)
      (check-equal?
       (parsable-as-datetime?"21 Jun 2015 15:45:40 -0000" 
"yyyy-MM-dd'T'HH:mm:ssxxx")
       #f)

but implementing them would take me longer than I have at the moment. (Maybe 
using an err lambda that doesn't throw an exception?)

I thought I'd check here: 
- does this seem like a reasonable idea?
- is mine an unusual use case and most folks know what format to expect and the 
exception approach is fine?
- is there perhaps an elegant way for me to test with a regular expression 
first rather than adding this function to Gregor?

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 racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/64c02e43-f693-475b-a8f4-05cf8f622c25%40googlegroups.com.

Reply via email to