feat: datetimes
This commit is contained in:
parent
829a933f35
commit
cb8c331468
28
toml.scm
28
toml.scm
|
@ -73,18 +73,17 @@
|
||||||
(('bool v)
|
(('bool v)
|
||||||
(equal? v "true"))
|
(equal? v "true"))
|
||||||
(('datetime v)
|
(('datetime v)
|
||||||
(car (strptime "%FT%T%z" v)))
|
(validate-date-time `(datetime ,v))
|
||||||
|
(datetime->date v))
|
||||||
(('datetime-local v)
|
(('datetime-local v)
|
||||||
(display "guile-toml: datetimes are currently not supported\n")
|
(validate-date-time `(datetime-local ,v))
|
||||||
v)
|
(datetime-local->date v))
|
||||||
(('date-local v)
|
(('date-local v)
|
||||||
(display "guile-toml: datetimes are currently not supported\n")
|
(validate-date-time `(date-local ,v))
|
||||||
v)
|
(date-local->date v))
|
||||||
(('time-local v)
|
(('time-local v)
|
||||||
(display "guile-toml: datetimes are currently not supported\n")
|
(validate-date-time `(time-local ,v))
|
||||||
v)
|
(time-local->date v))
|
||||||
|
|
||||||
|
|
||||||
((x y)
|
((x y)
|
||||||
(format #f "~a: ~a" x y))
|
(format #f "~a: ~a" x y))
|
||||||
('()
|
('()
|
||||||
|
@ -103,13 +102,22 @@
|
||||||
s-upcased))
|
s-upcased))
|
||||||
s-without-colon)
|
s-without-colon)
|
||||||
|
|
||||||
(define (datetime-string->date s)
|
(define (datetime->date s)
|
||||||
(define format (string-append
|
(define format (string-append
|
||||||
"~Y-~m-~dT~H:~M:~S"
|
"~Y-~m-~dT~H:~M:~S"
|
||||||
(if (string-contains s ".") ".~N" "")
|
(if (string-contains s ".") ".~N" "")
|
||||||
"~z"))
|
"~z"))
|
||||||
(string->date (normalize-date-time s) format))
|
(string->date (normalize-date-time s) format))
|
||||||
|
|
||||||
|
(define (datetime-local->date s)
|
||||||
|
(string->date (normalize-date-time s) "~Y-~m-~dT~H:~M:~S"))
|
||||||
|
|
||||||
|
(define (date-local->date s)
|
||||||
|
(string->date s "~Y~m~d"))
|
||||||
|
|
||||||
|
(define (time-local->date s)
|
||||||
|
(string->date s "~H:~M:~S"))
|
||||||
|
|
||||||
(define (remove-nanos s)
|
(define (remove-nanos s)
|
||||||
(define nanos (string-match "\\.[0-9]+" s))
|
(define nanos (string-match "\\.[0-9]+" s))
|
||||||
(define region (and nanos (vector-ref nanos 1)))
|
(define region (and nanos (vector-ref nanos 1)))
|
||||||
|
|
Loading…
Reference in New Issue