diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2021-01-14 00:56:08 +0100 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2021-01-14 01:12:19 +0100 |
commit | cd32027480400526806657612721882062bb010f (patch) | |
tree | 134c955ab3ba224f1dee5ec7c737b37ecbba314c /module | |
parent | Found js property documentElement. (diff) | |
download | calp-cd32027480400526806657612721882062bb010f.tar.gz calp-cd32027480400526806657612721882062bb010f.tar.xz |
Added string->date/-time.
Diffstat (limited to '')
-rw-r--r-- | module/datetime.scm | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/module/datetime.scm b/module/datetime.scm index 2f7e20c5..9abd1307 100644 --- a/module/datetime.scm +++ b/module/datetime.scm @@ -717,6 +717,16 @@ (define*-public (string->date str optional: (fmt "~Y-~m-~d")) (get-date (string->datetime str fmt))) +;; Parse @var{string} as either a date, time, or date-time. +;; String MUST be on iso-8601 format. +(define-public (string->date/-time string) + (define (contains symb) + (lambda (string) (string-contains string symb))) + + (cond [string (contains "T") => string->datetime] + [string (contains ":") => string->time] + [string (contains "-") => string->date])) + (define-public (parse-ics-date str) (string->date str "~Y~m~d")) @@ -757,15 +767,14 @@ time: ,(if verbose (time->sexp (get-time% dt)) (get-time% dt)) tz: ,(tz dt))) + (define (date-reader chr port) + (define (dt->sexp dt) (datetime->sexp dt #t) ) (unread-char chr port) - (let ((line (symbol->string (read port)))) - (cond [(string-contains line "T") - (-> line string->datetime (datetime->sexp #t))] - [(string-contains line ":") - (-> line string->time time->sexp)] - [(string-contains line "-") - (-> line string->date date->sexp)]))) + (let ((data (string->date/-time (symbol->string (read port))))) + (cond [data datetime? => dt->sexp] + [data time? => time->sexp] + [data date? => date->sexp]))) (read-hash-extend #\0 date-reader) (read-hash-extend #\1 date-reader) |