* How do you format date-times in RFC 3339 style?
@ 2019-02-11 19:02 sirgazil
2019-02-11 21:39 ` Nala Ginrut
0 siblings, 1 reply; 13+ messages in thread
From: sirgazil @ 2019-02-11 19:02 UTC (permalink / raw)
To: Guile User
Hi,
I'm generating atom feeds from SXML that don't validate because of the
date-time format I'm using:
> (use-modules (srfi srfi-19))
> (date->string (current-date) "~Y-~m-~dT~H:~M.~S~z")
$1 = "2019-02-11T13:42.57-0500"
String $1 is close to the RFC 3339 style,¹ which is the required format
for atom feeds, but the time zone offset should be -05:00, and Guile's
SRFI-19 ~z time zone escape is RFC 822 style, which formats the time
zone offset as -0500.
What should I do to get the offset in the required format?
Thanks,
_____
1. http://www.faqs.org/rfcs/rfc3339.html
--
Luis Felipe López Acevedo
http://sirgazil.bitbucket.io/
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: How do you format date-times in RFC 3339 style?
2019-02-11 19:02 sirgazil
@ 2019-02-11 21:39 ` Nala Ginrut
2019-02-11 21:40 ` Nala Ginrut
2019-02-12 14:33 ` sirgazil
0 siblings, 2 replies; 13+ messages in thread
From: Nala Ginrut @ 2019-02-11 21:39 UTC (permalink / raw)
To: sirgazil; +Cc: Guile User
Hi there!
Guile web module has provided an unexpected API for that:
(define write-date (@@ (web http) write-date))
sirgazil <sirgazil@zoho.com> 于 2019年2月12日周二 03:18写道:
> Hi,
>
> I'm generating atom feeds from SXML that don't validate because of the
> date-time format I'm using:
>
> > (use-modules (srfi srfi-19))
> > (date->string (current-date) "~Y-~m-~dT~H:~M.~S~z")
> $1 = "2019-02-11T13:42.57-0500"
>
> String $1 is close to the RFC 3339 style,¹ which is the required format
> for atom feeds, but the time zone offset should be -05:00, and Guile's
> SRFI-19 ~z time zone escape is RFC 822 style, which formats the time
> zone offset as -0500.
>
> What should I do to get the offset in the required format?
>
>
> Thanks,
>
>
> _____
>
> 1. http://www.faqs.org/rfcs/rfc3339.html
>
>
> --
> Luis Felipe López Acevedo
> http://sirgazil.bitbucket.io/
>
>
>
>
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: How do you format date-times in RFC 3339 style?
2019-02-11 21:39 ` Nala Ginrut
@ 2019-02-11 21:40 ` Nala Ginrut
2019-02-12 14:33 ` sirgazil
1 sibling, 0 replies; 13+ messages in thread
From: Nala Ginrut @ 2019-02-11 21:40 UTC (permalink / raw)
To: sirgazil; +Cc: Guile User
Sorry for typo from input corrector:
s/unexpected/unexport
Nala Ginrut <nalaginrut@gmail.com> 于 2019年2月12日周二 05:39写道:
> Hi there!
> Guile web module has provided an unexpected API for that:
>
> (define write-date (@@ (web http) write-date))
>
> sirgazil <sirgazil@zoho.com> 于 2019年2月12日周二 03:18写道:
>
>> Hi,
>>
>> I'm generating atom feeds from SXML that don't validate because of the
>> date-time format I'm using:
>>
>> > (use-modules (srfi srfi-19))
>> > (date->string (current-date) "~Y-~m-~dT~H:~M.~S~z")
>> $1 = "2019-02-11T13:42.57-0500"
>>
>> String $1 is close to the RFC 3339 style,¹ which is the required format
>> for atom feeds, but the time zone offset should be -05:00, and Guile's
>> SRFI-19 ~z time zone escape is RFC 822 style, which formats the time
>> zone offset as -0500.
>>
>> What should I do to get the offset in the required format?
>>
>>
>> Thanks,
>>
>>
>> _____
>>
>> 1. http://www.faqs.org/rfcs/rfc3339.html
>>
>>
>> --
>> Luis Felipe López Acevedo
>> http://sirgazil.bitbucket.io/
>>
>>
>>
>>
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: How do you format date-times in RFC 3339 style?
2019-02-11 21:39 ` Nala Ginrut
2019-02-11 21:40 ` Nala Ginrut
@ 2019-02-12 14:33 ` sirgazil
2019-02-12 16:18 ` Nala Ginrut
2019-02-12 16:50 ` Ricardo Wurmus
1 sibling, 2 replies; 13+ messages in thread
From: sirgazil @ 2019-02-12 14:33 UTC (permalink / raw)
To: Nala Ginrut; +Cc: Guile User
Hi, Nala :)
El 11/02/19 a las 4:39 p. m., Nala Ginrut escribió:
> Hi there!
> Guile web module has provided an unexpected API for that:
>
> (define write-date (@@ (web http) write-date))
I think I prefer using public procedures, so I'll leave the error there
for now.
But I'm curious, how do you get the time zone offset using `write-date`?
> (use-modules (srfi srfi-19))
>
> (define write-date (@@ (web http) write-date))
> (call-with-output-string (lambda (port) (write-date (current-date)
port)))
$1 = "Tue, 12 Feb 2019 14:23:52 GMT"
I was hoping `write-date` would write the date/time in RFC 3339 format
(https://tools.ietf.org/html/rfc3339#section-5.8).
> sirgazil <sirgazil@zoho.com <mailto:sirgazil@zoho.com>> 于 2019年2月12日
> 周二 03:18写道:
>
> Hi,
>
> I'm generating atom feeds from SXML that don't validate because of the
> date-time format I'm using:
>
> > (use-modules (srfi srfi-19))
> > (date->string (current-date) "~Y-~m-~dT~H:~M.~S~z")
> $1 = "2019-02-11T13:42.57-0500"
>
> String $1 is close to the RFC 3339 style,¹ which is the required format
> for atom feeds, but the time zone offset should be -05:00, and Guile's
> SRFI-19 ~z time zone escape is RFC 822 style, which formats the time
> zone offset as -0500.
>
> What should I do to get the offset in the required format?
>
>
> Thanks,
>
>
> _____
>
> 1. http://www.faqs.org/rfcs/rfc3339.html
>
>
> --
> Luis Felipe López Acevedo
> http://sirgazil.bitbucket.io/
>
>
>
--
Luis Felipe López Acevedo
http://sirgazil.bitbucket.io/
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: How do you format date-times in RFC 3339 style?
2019-02-12 14:33 ` sirgazil
@ 2019-02-12 16:18 ` Nala Ginrut
2019-02-12 17:33 ` sirgazil
2019-02-12 16:50 ` Ricardo Wurmus
1 sibling, 1 reply; 13+ messages in thread
From: Nala Ginrut @ 2019-02-12 16:18 UTC (permalink / raw)
To: sirgazil; +Cc: Guile User
Sorry for the misleading, what I thought is RFC1123. Please ingnore my
answer. :-(
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: How do you format date-times in RFC 3339 style?
2019-02-12 14:33 ` sirgazil
2019-02-12 16:18 ` Nala Ginrut
@ 2019-02-12 16:50 ` Ricardo Wurmus
2019-02-12 18:15 ` sirgazil
1 sibling, 1 reply; 13+ messages in thread
From: Ricardo Wurmus @ 2019-02-12 16:50 UTC (permalink / raw)
To: sirgazil; +Cc: Guile User
sirgazil <sirgazil@zoho.com> writes:
> El 11/02/19 a las 4:39 p. m., Nala Ginrut escribió:
>> Hi there!
>> Guile web module has provided an unexpected API for that:
>>
>> (define write-date (@@ (web http) write-date))
>
>
> I think I prefer using public procedures, so I'll leave the error
> there for now.
I suppose you could hack your way around this:
(use-modules (srfi srfi-19))
(let* ((now (current-date))
(tz (date->string now "~z")))
(string-append (date->string now "~Y-~m-~dT~H:~M.~S")
(string-drop-right tz 2) ":" (string-take-right tz 2)))
What do you think?
--
Ricardo
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: How do you format date-times in RFC 3339 style?
2019-02-12 16:18 ` Nala Ginrut
@ 2019-02-12 17:33 ` sirgazil
0 siblings, 0 replies; 13+ messages in thread
From: sirgazil @ 2019-02-12 17:33 UTC (permalink / raw)
To: Nala Ginrut; +Cc: Guile User
El 12/02/19 a las 11:18 a. m., Nala Ginrut escribió:
> Sorry for the misleading, what I thought is RFC1123. Please ingnore my
> answer. :-(
Ha ha, no problem, Nala :)
--
Luis Felipe López Acevedo
http://sirgazil.bitbucket.io/
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: How do you format date-times in RFC 3339 style?
2019-02-12 16:50 ` Ricardo Wurmus
@ 2019-02-12 18:15 ` sirgazil
0 siblings, 0 replies; 13+ messages in thread
From: sirgazil @ 2019-02-12 18:15 UTC (permalink / raw)
To: Ricardo Wurmus; +Cc: Guile User
El 12/02/19 a las 11:50 a. m., Ricardo Wurmus escribió:
>
> sirgazil <sirgazil@zoho.com> writes:
>
>> El 11/02/19 a las 4:39 p. m., Nala Ginrut escribió:
>>> Hi there!
>>> Guile web module has provided an unexpected API for that:
>>>
>>> (define write-date (@@ (web http) write-date))
>>
>>
>> I think I prefer using public procedures, so I'll leave the error
>> there for now.
>
> I suppose you could hack your way around this:
>
> (use-modules (srfi srfi-19))
> (let* ((now (current-date))
> (tz (date->string now "~z")))
> (string-append (date->string now "~Y-~m-~dT~H:~M.~S")
> (string-drop-right tz 2) ":" (string-take-right tz 2)))
>
> What do you think?
Well, I was trying to avoid that hoping to find an obscure RFC 3339
module or something first... But thanks, Ricardo :)
--
Luis Felipe López Acevedo
http://sirgazil.bitbucket.io/
^ permalink raw reply [flat|nested] 13+ messages in thread
* How do you format date-times in RFC 3339 style?
@ 2019-02-12 18:29 tantalum
0 siblings, 0 replies; 13+ messages in thread
From: tantalum @ 2019-02-12 18:29 UTC (permalink / raw)
To: sirgazil; +Cc: guile-user
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
for reference, the complete code: https://github.com/sph-mn/sph-lib/blob/master/modules/sph/time/rfc3339.scm
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: How do you format date-times in RFC 3339 style?
@ 2019-02-12 18:33 tantalum
2019-02-13 14:21 ` sirgazil
0 siblings, 1 reply; 13+ messages in thread
From: tantalum @ 2019-02-12 18:33 UTC (permalink / raw)
To: sirgazil; +Cc: Guile user
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
for reference, the complete code:
https://github.com/sph-mn/sph-lib/blob/master/modules/sph/time/rfc3339.scm
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: How do you format date-times in RFC 3339 style?
2019-02-12 18:33 How do you format date-times in RFC 3339 style? tantalum
@ 2019-02-13 14:21 ` sirgazil
2019-02-14 19:26 ` tantalum
0 siblings, 1 reply; 13+ messages in thread
From: sirgazil @ 2019-02-13 14:21 UTC (permalink / raw)
To: sph; +Cc: Guile user
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/
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: How do you format date-times in RFC 3339 style?
2019-02-13 14:21 ` sirgazil
@ 2019-02-14 19:26 ` tantalum
2019-02-14 21:13 ` Ricardo Wurmus
0 siblings, 1 reply; 13+ messages in thread
From: tantalum @ 2019-02-14 19:26 UTC (permalink / raw)
To: sirgazil; +Cc: Guile user
> You know what would be great? If you packaged "sph-lib" for GNU Guix
that is a good point, i plan on trying to do that, again. with the last
two tries i couldnt find a simple example or documentation for creating
a guix package that doesnt use autotools.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: How do you format date-times in RFC 3339 style?
2019-02-14 19:26 ` tantalum
@ 2019-02-14 21:13 ` Ricardo Wurmus
0 siblings, 0 replies; 13+ messages in thread
From: Ricardo Wurmus @ 2019-02-14 21:13 UTC (permalink / raw)
To: sph; +Cc: Guile user
tantalum <sph@posteo.eu> writes:
>> You know what would be great? If you packaged "sph-lib" for GNU Guix
>
> that is a good point, i plan on trying to do that, again. with the
> last two tries i couldnt find a simple example or documentation for
> creating a guix package that doesnt use autotools.
You can use the guile-build-system. You can look at
guile-picture-language in gnu/packages/guile-xyz.scm in the Guix sources
for an example.
--
Ricardo
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2019-02-14 21:13 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-02-12 18:33 How do you format date-times in RFC 3339 style? tantalum
2019-02-13 14:21 ` sirgazil
2019-02-14 19:26 ` tantalum
2019-02-14 21:13 ` Ricardo Wurmus
-- strict thread matches above, loose matches on Subject: below --
2019-02-12 18:29 tantalum
2019-02-11 19:02 sirgazil
2019-02-11 21:39 ` Nala Ginrut
2019-02-11 21:40 ` Nala Ginrut
2019-02-12 14:33 ` sirgazil
2019-02-12 16:18 ` Nala Ginrut
2019-02-12 17:33 ` sirgazil
2019-02-12 16:50 ` Ricardo Wurmus
2019-02-12 18:15 ` sirgazil
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).