[plt-scheme] on the absence of some strftime

From: YC (yinso.chen at gmail.com)
Date: Mon Dec 28 18:43:09 EST 2009

If you want to work with PLT dates instead of srfi/19 dates, I have most of
the srfi/19 functions wrapped/exported for PLT dates with bzlib/date/plt.

> (require (planet bzlib/date/plt))
> (current-date) ;; returns PLT date instead of srfi/19 date

However, date->string is not currently wrapped from srfi/19.  But you can
use bzlib/date/convert and date/plt->srfi/19 to your own date->string
wrapper.

> (require (prefix-in s: srfi/19) (planet bzlib/date/convert))
> (define (date->string date (format "~c")) ;; wrapper over srfi/19's
date->string
    (s:date->string (date/plt->srfi/19 date) format))

Then you can use the format string defined for
SRFI/19<http://srfi.schemers.org/srfi-19/srfi-19.html>to do your
formatting for plt dates.

> (date->string (current-date) "~a, ~e ~b ~Y ~T ~z")
"Mon, 28 Dec 2009 18:35:27 -0500"

If you just need RFC822 it is also implemented as date->rfc822

> (date->rfc822 (current-date))
"Mon, 28 Dec 2009 18:35:27 -0500"

You can find more usages of bzlib/date at
http://weblambda.blogspot.com/2009/10/bzlibdate-bzlibdate-tz-02-now-available.html-
let me know if there are any questions/issues/comments.

Cheers,
yc

On Mon, Dec 28, 2009 at 2:49 PM, David Brown <plt at davidb.org> wrote:

> On Mon, Dec 28, 2009 at 09:04:07PM +0000, Daniel Bastos wrote:
>
>  I miss a PLT function such as strftime. I can't find anything like it,
>> in the reference, and on the web. I would like to easily produce a
>> string such as ``Mon Dec 28 21:56:33 CET 2009.'' The closest to it to
>> choose the format of 'rfc2822.
>>
>
> srfi/19 has a date->string converter, however it wants an srfi/19 date
> instead of the PLT date.  If you don't need to convert between them,
> it's fairly easy, otherwise, you'd have to figure out if the julian
> conversions are the same and convert between them.
>
> David
>
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20091228/55a9c8cf/attachment.html>

Posted on the users mailing list.