Hi, tantalum.
El 12/02/19 a las 1:33 p. m., tantalum escribió:
i once wrote a rfc3339 reader/writer and worked through some gotchas,
maybe the code contains hints that are helpful.
for example, here is a function that converts from a timestamp to a
rfc3339 date string:
(define* (utc->rfc3339 a #:optional (offset 0) (seconds-fraction 0))
"integer:posix-time -> string"
(let
( (date-time
(let (t (gmtime (+ a offset)))
(apply
(l (y m d h mi s)
(string-append y "-"
m "-"
d "T"
h ":"
mi ":"
s
(if (zero? seconds-fraction) ""
(string-append "." (number->string
seconds-fraction)))))
(map number->padded-string
(list (+ 1900 (tm:year t)) (+ 1 (tm:mon t))
(tm:mday t) (tm:hour t) (tm:min t) (tm:sec t))))))
(offset
(if (zero? offset) "Z"
(apply
(l (sign numbers)
(string-append sign (string-join (map
number->padded-string numbers) ":")))
(let* ((hms (drop-right (utc-duration->hms offset) 1))
(hours (first hms)))
(if (any negative? hms) (list "-" (map (l (a) (* -1 a))
hms)) (list "+" hms)))))))
(string-append date-time offset)))
l: lambda, first: car
the code passes these tests (examples of valid strings):
https://github.com/sph-mn/sph-lib/blob/master/modules/test/module/sph/time/rfc3339.scm
From these tests, I think this could work for me, thanks.
for reference, the complete code:
https://github.com/sph-mn/sph-lib/blob/master/modules/sph/time/rfc3339.scm
You know what would be great? If you packaged "sph-lib" for GNU Guix :)
That way I could easily install it and your library would be visible in
the list of packages in Guile website.
--
Luis Felipe López Acevedo
http://sirgazil.bitbucket.io/