s c h e m a t i c s : c o o k b o o k

/ Cookbook.TimeRFC822

This Web


WebHome 
WebChanges 
TOC (with recipes)
NewRecipe 
WebTopicList 
WebStatistics 

Other Webs


Chicken
Cookbook
Erlang
Know
Main
Plugins
Sandbox
Scm
TWiki  

Schematics


Schematics Home
Sourceforge Page
SchemeWiki.org
Original Cookbook
RSS

Scheme Links


Schemers.org
Scheme FAQ
R5RS
SRFIs
Scheme Cross Reference
PLT Scheme SISC
Scheme48 SCM
MIT Scheme scsh
JScheme Kawa
Chicken Guile
Bigloo Tiny
Gambit LispMe
GaucheChez

Lambda the Ultimate
TWiki.org

Writing and Parsing RFC 822 Dates and Times

Problem

You need to convert from struct:time to RFC 822 format Dates and Times.

Solution

mzlib provides one solution:
> (require (lib "date.ss"))
> (date-display-format 'rfc2822)
> (date->string (seconds->date (current-seconds)) #t)
"Wed, 28 Apr 2004 10:37:20 -0600"

However, many applications that use RFC 822 require all output in GMT. mzlib's seconds->date assumes the current timezone, but SRFI 19 allows you to specify a time zone in the 2nd argument to seconds->date-utc.

> (require (lib "time.ss" "srfi" "19"))
> (date->string (time-utc->date (current-time) ) "~a, ~d ~b ~Y ~T ~z" )
"Wed, 28 Apr 2004 11:21:53 -0600"
> (date->string (time-utc->date (current-time) 0) "~a, ~d ~b ~Y ~T ~z" )
"Wed, 28 Apr 2004 17:22:10 Z"
%end scheme%

If you need to parse dates as input, you can use =string->date= from SRFI 19:
%begin scheme%
> (string->date "Wed, 28 Apr 2004 17:22:10 Z" "~a, ~d ~b ~Y ~H:~M:~S ~z" )
#<struct:date>

Discussion

RFC 822 is used frequently as the basis for exchanging dates and times, particularly in Internet applications. You should also be aware that the struct:date provided by mzlib is not compatible with SRFI 19's struct:date, so you should pick one and stick with it, to avoid mixing types.

References

[RFC 822 [RFC 1123

-- GordonWeakliem - 28 Apr 2004

 
 
Copyright © 2004 by the contributing authors. All material on the Schematics Cookbook web site is the property of the contributing authors.
The copyright for certain compilations of material taken from this website is held by the SchematicsEditorsGroup - see ContributorAgreement & LGPL.
Other than such compilations, this material can be redistributed and/or modified under the terms of the GNU Lesser General Public License (LGPL), version 2.1, as published by the Free Software Foundation.
Ideas, requests, problems regarding Schematics Cookbook? Send feedback.
/ You are Main.guest