summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEkaitz Zarraga <ekaitz@elenq.tech>2023-10-15 11:58:10 +0200
committerEkaitz Zarraga <ekaitz@elenq.tech>2023-10-15 11:58:10 +0200
commit977db3799cafbbdec3751112dfe3234e443a81c1 (patch)
treee1434ad5c8b9b36b85fc95ddea110d9ea85944d2 /src
parent33c097bc39b7c8d8e436a78daa78e5fdc489b964 (diff)
dates: conform RFC-3339 standard
Diffstat (limited to 'src')
-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"))