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 +++++++++++++----- module/vcomponent/parse.scm | 4 ++-- module/vcomponent/recurrence/generate.scm | 2 +- module/vcomponent/recurrence/parse.scm | 2 +- 4 files changed, 17 insertions(+), 9 deletions(-) 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)) diff --git a/module/vcomponent/parse.scm b/module/vcomponent/parse.scm index 8efa9e62..7ae966a1 100644 --- a/module/vcomponent/parse.scm +++ b/module/vcomponent/parse.scm @@ -210,9 +210,9 @@ row ~a column ~a ctx = ~a (let ((type (and=> (prop it 'VALUE) car))) (if (or (and=> type (cut string=? <> "DATE-TIME")) (string-contains (value it) "T")) - (set! (value it) (parse-datetime (value it) tz) + (set! (value it) (parse-ics-datetime (value it) tz) (prop it 'VALUE) 'DATE-TIME) - (set! (value it) (parse-date (value it)) + (set! (value it) (parse-ics-date (value it)) (prop it 'VALUE) 'DATE))))]) diff --git a/module/vcomponent/recurrence/generate.scm b/module/vcomponent/recurrence/generate.scm index ee59ed04..c03a935a 100644 --- a/module/vcomponent/recurrence/generate.scm +++ b/module/vcomponent/recurrence/generate.scm @@ -159,7 +159,7 @@ event (parse-recurrence-rule (attr event "RRULE") (if (date? (attr event 'DTSTART)) - parse-date parse-datetime))) + parse-ics-date parse-ics-datetime))) ;; TODO some events STANDARD and DAYLIGT doesn't have RRULE's, but rather ;; just mention the current part. Handle this stream-null)))) diff --git a/module/vcomponent/recurrence/parse.scm b/module/vcomponent/recurrence/parse.scm index 97e5e980..00d9fcdb 100644 --- a/module/vcomponent/recurrence/parse.scm +++ b/module/vcomponent/recurrence/parse.scm @@ -51,7 +51,7 @@ ;; RFC 5545, Section 3.3.10. Recurrence Rule, states that the UNTIL value MUST have ;; the same type as the DTSTART of the event (date or datetime). I have seen events ;; in the wild which didn't follow this. I consider that an user error. -(define* (parse-recurrence-rule str optional: (datetime-parser parse-datetime)) +(define* (parse-recurrence-rule str optional: (datetime-parser parse-ics-datetime)) (fold (lambda (kv o) (let* (((key val) kv)) -- cgit v1.2.3