From 4889e9fc9d4756803c0eb7f700ecd32fcfa61404 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Tue, 31 Mar 2020 00:38:00 +0200 Subject: Rename parse-date to parse-ics-date, add parse-iso-date. --- module/datetime.scm | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'module/datetime.scm') diff --git a/module/datetime.scm b/module/datetime.scm index 4fef907f..30fb6025 100644 --- a/module/datetime.scm +++ b/module/datetime.scm @@ -657,22 +657,22 @@ (define (s->n str from to) (string->number (substring/read-only str from to))) -(define-public (parse-date str) +(define-public (parse-ics-date str) (date year: (s->n str 0 4) month: (s->n str 4 6) day: (s->n str 6 8))) -(define-public (parse-time str) +(define-public (parse-ics-time str) (time hour: (s->n str 0 2) minute: (s->n str 2 4) second: (s->n str 4 6))) -(define*-public (parse-datetime str optional: tz) +(define*-public (parse-ics-datetime str optional: tz) (unless (string-any #\T str) (throw 'parse-error "String ~a doesn't look like a valid datetime" str)) (let* (((datestr timestr) (string-split str #\T))) - (datetime date: (parse-date datestr) - time: (parse-time timestr) + (datetime date: (parse-ics-date datestr) + time: (parse-ics-time timestr) tz: tz))) @@ -691,6 +691,10 @@ (let* (((year month day) (map string->number (string-split str #\-)))) `(date year: ,year month: ,month day: ,day))) +(define-public (parse-iso-date str) + (let* (((year month day) (map string->number (string-split str #\-)))) + (date year: year month: month day: day))) + (define (parse-time% timestr) (let* (((hour minute second) (string-split timestr #\:))) (let ((hour (string->number hour)) @@ -698,6 +702,10 @@ (second (string->number second))) `(time hour: ,hour minute: ,minute second: ,second)))) +(define-public (parse-iso-time str) + (let* (((hour minute second) (map string->number (string-split str #\:)))) + (time hour: hour minute: minute second: second))) + (define (parse-datetime% str) (let* (((date time) (string-split str #\T))) (when (string= "Z" (string-take-right str 1)) -- cgit v1.2.3