From 993aec0b17086cc4681fbf234aa19f4710fff441 Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Fri, 24 Jun 2022 00:30:03 +0530 Subject: issue: Add serialization and deserialization functions. * tissue/issue.scm (date->iso-8601, iso-8601->date): New functions. (issue->alist, post->alist, alist->issue, alist->post): New public functions. --- tissue/issue.scm | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/tissue/issue.scm b/tissue/issue.scm index 8f36d94..3b6c015 100644 --- a/tissue/issue.scm +++ b/tissue/issue.scm @@ -48,6 +48,10 @@ post post-author post-date + issue->alist + alist->issue + post->alist + alist->post authors issues)) @@ -81,6 +85,57 @@ (author post-author) (date post-date)) +(define (date->iso-8601 date) + "Convert DATE, an SRFI-19 date object, to an ISO-8601 date string." + (date->string date "~4")) + +(define (iso-8601->date str) + "Convert STR, an ISO-8601 date string, to an SRFI-19 date object." + (string->date str "~Y-~m-~dT~H:~M:~S~z")) + +(define (issue->alist issue) + "Convert ISSUE, a object, to an association list that can be +serialized." + `((file . ,(issue-file issue)) + (title . ,(issue-title issue)) + (creator . ,(issue-creator issue)) + (created-date . ,(date->iso-8601 (issue-created-date issue))) + (last-updater . ,(issue-last-updater issue)) + (last-updated-date . ,(date->iso-8601 (issue-last-updated-date issue))) + (assigned . ,(issue-assigned issue)) + (keywords . ,(issue-keywords issue)) + (open . ,(issue-open? issue)) + (tasks . ,(issue-tasks issue)) + (completed-tasks . , (issue-completed-tasks issue)) + (posts . ,(map post->alist (issue-posts issue))))) + +(define (post->alist post) + "Convert POST, a object, to an association list that can be +serialized." + `((author . ,(post-author post)) + (date . ,(date->iso-8601 (post-date post))))) + +(define (alist->issue alist) + "Convert ALIST to an object." + (issue (assq-ref alist 'file) + (assq-ref alist 'title) + (assq-ref alist 'creator) + (iso-8601->date (assq-ref alist 'created-date)) + (assq-ref alist 'last-updater) + (iso-8601->date (assq-ref alist 'last-updated-date)) + (assq-ref alist 'assigned) + (assq-ref alist 'keywords) + (assq-ref alist 'open) + (assq-ref alist 'tasks) + (assq-ref alist 'completed-tasks) + (map alist->post + (assq-ref alist 'posts)))) + +(define (alist->post alist) + "Convert ALIST to a object." + (post (assq-ref alist 'author) + (iso-8601->date (assq-ref alist 'date)))) + (define (hashtable-append! hashtable key new-values) "Append NEW-VALUES to the list of values KEY is associated to in HASHTABLE. Deduplicate the resulting list if necessary. If KEY is not -- cgit v1.2.3