From: Siraaj Khandkar Date: Tue, 16 Mar 2021 10:44:34 +0000 (-0400) Subject: WIP X-Git-Url: https://git.xandkar.net/?a=commitdiff_plain;h=0016b0ad6fd8960ad2eadd2686e98b146a953a0a;p=tt.git WIP --- diff --git a/info.rkt b/info.rkt index d6eb526..439516e 100644 --- a/info.rkt +++ b/info.rkt @@ -10,7 +10,7 @@ (define pkg-authors '("Siraaj Khandkar ")) (define deps - '("base" "http-client" "rfc3339-old")) + '("base" "http-client")) (define racket-launcher-names '("tt")) (define racket-launcher-libraries diff --git a/tt.rkt b/tt.rkt index ebbecad..dae32a7 100644 --- a/tt.rkt +++ b/tt.rkt @@ -41,9 +41,9 @@ (require openssl/sha1) (require racket/date) +(require (prefix-in srfi/19: srfi/19)) (require http-client) -(require rfc3339-old) (module+ test (require rackunit)) @@ -109,6 +109,15 @@ ; TODO Zulu offset. Maybe in several formats. Which ones? (pregexp "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}")) +(define (rfc3339->epoch str) + (with-handlers + ([exn? (λ (e) (log-error "Timestamp parse failure of ~v with ~v" str e))]) + ((srfi/19:time-second + (srfi/19:date->time-utc + (srfi/19:string->date + str + "~Y-~m-~dT~2")))))) + (define (str->msg nick uri str) (if (not (regexp-match? re-msg-begin str)) (begin @@ -122,14 +131,7 @@ (let* ([ts_rfc3339 (first toks)] [text (second toks)] - [t (string->rfc3339-record ts_rfc3339)] - ; TODO handle tz offset - [ts_epoch (find-seconds [rfc3339-record:second t] - [rfc3339-record:minute t] - [rfc3339-record:hour t] - [rfc3339-record:mday t] - [rfc3339-record:month t] - [rfc3339-record:year t])]) + [ts_epoch (rfc3339->epoch ts_rfc3339)]) (msg ts_epoch ts_rfc3339 nick uri text)))))) (module+ test @@ -140,11 +142,10 @@ [uri "bar"] [actual (str->msg nick uri (string-append ts tab text))] [expected (msg 1605756129 ts nick uri text)]) - ; FIXME re-enable after handling tz offset - ;(check-equal? - ; (msg-ts_epoch actual) - ; (msg-ts_epoch expected) - ; "str->msg ts_epoch") + (check-equal? + (msg-ts_epoch actual) + (msg-ts_epoch expected) + "str->msg ts_epoch") (check-equal? (msg-ts_rfc3339 actual) (msg-ts_rfc3339 expected)