Add parser for datetime property values
This commit is contained in:
parent
79f8c34c6c
commit
aaa6d5b292
28
vcarded.scm
28
vcarded.scm
|
@ -30,7 +30,7 @@
|
||||||
|
|
||||||
;; List of all properties with datetime values.
|
;; List of all properties with datetime values.
|
||||||
(define vcard-datetime-properties
|
(define vcard-datetime-properties
|
||||||
'(ANNIVERSARY BDAY REV TZ))
|
'(ANNIVERSARY BDAY REV))
|
||||||
|
|
||||||
|
|
||||||
;; List of all properties with multiple comma-separated values.
|
;; List of all properties with multiple comma-separated values.
|
||||||
|
@ -45,10 +45,22 @@
|
||||||
SOUND SOURCE TEL UID URL))
|
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.
|
;; A list of the parser/serializer functions for each vcard property.
|
||||||
;; ((TEL #<procedure> #<procedure>)
|
;; ((TEL #<procedure> #<procedure>)
|
||||||
;; (ADR #<procedure> #<procedure>)
|
;; (ADR #<procedure> #<procedure>)
|
||||||
;; …)
|
;; …)
|
||||||
|
;; TODO: Add a parser for the TZ [timezone] property.
|
||||||
(define vcard-value-parsers
|
(define vcard-value-parsers
|
||||||
(append
|
(append
|
||||||
(map (lambda (uri-prop)
|
(map (lambda (uri-prop)
|
||||||
|
@ -57,11 +69,17 @@
|
||||||
(string-join sts ";")))
|
(string-join sts ";")))
|
||||||
(lambda (url) (uri:uri->string url))))
|
(lambda (url) (uri:uri->string url))))
|
||||||
vcard-url-properties)
|
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)
|
(map (lambda (csv-prop)
|
||||||
(list csv-prop
|
(list csv-prop
|
||||||
(lambda (str) (string-split-unescaped str ","))
|
(lambda (str) (string-split-unescaped str ","))
|
||||||
(lambda (csv-list) (string-join csv-list ","))))
|
(lambda (csv-list) (string-join csv-list ","))))
|
||||||
vcard-csv-properties)
|
vcard-csv-properties)
|
||||||
(map (lambda (semicolon-prop)
|
(map (lambda (semicolon-prop)
|
||||||
(list semicolon-prop
|
(list semicolon-prop
|
||||||
(lambda (str) (string-split-unescaped str ";"))
|
(lambda (str) (string-split-unescaped str ";"))
|
||||||
|
|
Ŝarĝante…
Reference in New Issue