summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/dates.scm22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/dates.scm b/src/dates.scm
index e9c9b0c..a70aa01 100644
--- a/src/dates.scm
+++ b/src/dates.scm
@@ -1,4 +1,5 @@
(define-module (src dates)
+ #:use-module (ice-9 format)
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-19)
#:export (string/ISO->date
@@ -12,7 +13,26 @@
(string->date string "~Y-~m-~d"))
(define (date->string/RFC3339 date)
- (date->string date "~4"))
+ (call-with-output-string
+ (lambda (p)
+ (let* ((offset (abs (date-zone-offset date)))
+ (rem-h-seconds (modulo offset (* 60 60)))
+ (offset-hours (floor (/ (- offset rem-h-seconds) 60 60)))
+ (rem-m-seconds (modulo rem-h-seconds 60))
+ (offset-minutes (floor (/ (- rem-h-seconds rem-m-seconds) 60))))
+ (format
+ p
+ "~4,'0d-~2,'0d-~2,'0dT~2,'0d:~2,'0d:~2,'0d~:[Z~;~c~2,'0d:~2,'0d~]"
+ (date-year date)
+ (date-month date)
+ (date-day date)
+ (date-hour date)
+ (date-minute date)
+ (date-second date)
+ (not (= 0 (date-zone-offset date)))
+ (if (< 0 (date-zone-offset date)) #\+ #\-)
+ offset-hours
+ offset-minutes)))))
(define unix-date (string/ISO->date "1970-01-01"))