diff --git a/vcarded.scm b/vcarded.scm index 53fc978..1845e84 100644 --- a/vcarded.scm +++ b/vcarded.scm @@ -30,7 +30,7 @@ ;; List of all properties with datetime values. (define vcard-datetime-properties - '(ANNIVERSARY BDAY REV TZ)) + '(ANNIVERSARY BDAY REV)) ;; List of all properties with multiple comma-separated values. @@ -45,10 +45,22 @@ SOUND SOURCE TEL UID URL)) +;; Should parse any truncated & reduced-accuracy ISO 8601 datetime. +;; … right now, it only parses a few possibilities. +(define (string->any-date str) + (let* [(ymd "~Y~m~d") + (hms "~H~M~S") + (ymd-hms (string-join (list ymd hms) "T"))] + (or (ignore-error (string->date str ymd-hms) #f) + (ignore-error (string->date str ymd) #f) + (ignore-error (string->date str hms) #f)))) + + ;; A list of the parser/serializer functions for each vcard property. ;; ((TEL # #) ;; (ADR # #) ;; …) +;; TODO: Add a parser for the TZ [timezone] property. (define vcard-value-parsers (append (map (lambda (uri-prop) @@ -57,11 +69,17 @@ (string-join sts ";"))) (lambda (url) (uri:uri->string url)))) vcard-url-properties) + (map (lambda (date-prop) + (list date-prop + string->any-date + (lambda (datetime) + (date->string datetime "~Y~m~dT~H~M~S~z")))) + vcard-datetime-properties) (map (lambda (csv-prop) - (list csv-prop - (lambda (str) (string-split-unescaped str ",")) - (lambda (csv-list) (string-join csv-list ",")))) - vcard-csv-properties) + (list csv-prop + (lambda (str) (string-split-unescaped str ",")) + (lambda (csv-list) (string-join csv-list ",")))) + vcard-csv-properties) (map (lambda (semicolon-prop) (list semicolon-prop (lambda (str) (string-split-unescaped str ";"))