diff options
-rw-r--r-- | readers/article.rkt | 7 | ||||
-rw-r--r-- | utils/date.rkt | 22 |
2 files changed, 26 insertions, 3 deletions
diff --git a/readers/article.rkt b/readers/article.rkt index df5e8e8..c60de16 100644 --- a/readers/article.rkt +++ b/readers/article.rkt @@ -3,7 +3,8 @@ (provide read-article) (require "../entities/article.rkt") -(require (only-in typed/srfi/19 string->date)) +(require (only-in "../utils/date.rkt" string->date)) + (require typed/json) (require typed/syntax/readerr) @@ -19,9 +20,9 @@ (define timestamp (let ([timestamp (hash-ref jse 'timestamp (thunk (k "timestamp not found")))]) (unless (string? timestamp) (k "timestamp must be a string")) - (with-handlers ([exn:fail? (const #f)]) + (with-handlers ([exn:fail? (lambda (_e) + (k "timestamp must be a iso8600 string"))]) (string->date timestamp "~Y-~m-~dT~H:~M:~S~z")))) - (unless (date? timestamp) (k "timestamp must be a iso8600 string")) (define hash (hash-ref jse 'hash (thunk (k "hash not found")))) (unless (string? hash) (k "hash must be a string")) diff --git a/utils/date.rkt b/utils/date.rkt new file mode 100644 index 0000000..7019832 --- /dev/null +++ b/utils/date.rkt @@ -0,0 +1,22 @@ +#lang typed/racket + +(provide current-date + string->date + date->string) + +(require (only-in typed/racket/date current-date)) +(require (rename-in (only-in typed/srfi/19 + string->date + date->string + date?) + [string->date string->Date] + [date->string Date->string] + [date? Date?])) + +(: string->date (-> String String date)) +(define (string->date str fmt) + (assert (string->Date str fmt) date?)) + +(: date->string (->* (date) (String) String)) +(define (date->string d [f "~c"]) + (Date->string (assert d Date?) f)) |