#lang scheme/base
(require "base.ss" "date.ss" "depend.ss" "rfc822.ss")
(define date
(seq year <- digit4
(zero-one #\- #f)
month <- digit2
(zero-one #\- #f)
day <- digit2
(return (list year month day))))
(define time
(seq hour <- digit2
(zero-one #\: #f)
minute <- digit2
(zero-one #\: #f)
seconds <- digit2
(return (list hour minute seconds))))
(define timezone
(choice (seq #\Z (return 0))
(seq #\z (return 0))
(seq sign <- (zero-one (choice (seq #\+ (return +))
(seq #\- (return -)))
+)
hour <- digit2
(zero-one #\: #f)
minute <- digit2
(return (sign (offset hour minute))))))
(define iso8601
(seq d <- date
time+zone <-
(zero-one (seq (zero-one #\T #f)
t <- time
zone <- (zero-one timezone 0)
(return (append t (list '#:tz zone))))
`(0 0 0 #:tz 0))
(return (apply* build-date (append d time+zone)))))
(define read-iso8601 (make-reader iso8601))
(define (date->iso8601 d)
(date->string d "~Y~m~dT~H~M~S~z"))
(provide/contract
(read-iso8601 Reader/c)
(date->iso8601 (-> date? string?))
)