Add support for generating the HTTP date strings: required use of
authorChris Hanson <org/chris-hanson/cph>
Mon, 25 Aug 2008 08:37:35 +0000 (08:37 +0000)
committerChris Hanson <org/chris-hanson/cph>
Mon, 25 Aug 2008 08:37:35 +0000 (08:37 +0000)
"GMT" time zone marker.  Also export the parser for iso8601 time.

v7/src/runtime/datime.scm
v7/src/runtime/runtime.pkg

index 8de63ac7dc890a78eca461a6a2f9c577b8c82240..eaae4a27de41a4c9e49dd91684907377f0743d26 100644 (file)
@@ -1,6 +1,6 @@
 #| -*-Scheme-*-
 
-$Id: datime.scm,v 14.44 2008/01/30 20:02:29 cph Exp $
+$Id: datime.scm,v 14.45 2008/08/25 08:37:32 cph Exp $
 
 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
     1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
@@ -198,13 +198,22 @@ USA.
 (define (universal-time->global-time-string time)
   (decoded-time->string (universal-time->global-decoded-time time)))
 
+(define (universal-time->http-string time)
+  (decoded-time->http-string (universal-time->global-decoded-time time)))
+
 (define (file-time->local-time-string time)
   (decoded-time->string (file-time->local-decoded-time time)))
 
 (define (file-time->global-time-string time)
   (decoded-time->string (file-time->global-decoded-time time)))
 
-(define (decoded-time->string dt)
+(define (file-time->http-string time)
+  (decoded-time->http-string (file-time->global-decoded-time time)))
+
+(define (decoded-time->string dt) (%decoded-time->string dt #f))
+(define (decoded-time->http-string dt) (%decoded-time->string dt #t))
+
+(define (%decoded-time->string dt http?)
   ;; The returned string is in the format specified by RFC 822,
   ;; "Standard for the Format of ARPA Internet Text Messages",
   ;; provided that time-zone information is available from the C
@@ -224,15 +233,17 @@ USA.
                 (d2 (decoded-time/minute dt))
                 ":"
                 (d2 (decoded-time/second dt))
-                (let ((zone (decoded-time/zone dt)))
-                  (if zone
-                      (string-append
-                       " "
-                       (time-zone->string
-                        (if (decoded-time/daylight-savings-time? dt)
-                            (- zone 1)
-                            zone)))
-                      ""))))
+                (if http?
+                    " GMT"
+                    (let ((zone (decoded-time/zone dt)))
+                      (if zone
+                          (string-append
+                           " "
+                           (time-zone->string
+                            (if (decoded-time/daylight-savings-time? dt)
+                                (- zone 1)
+                                zone)))
+                          "")))))
 \f
 (define (string->decoded-time string)
   ;; STRING must be in RFC-822 format.
@@ -397,8 +408,8 @@ USA.
 ;;; support either truncation or expansion.  On output, it uses a
 ;;; single format.
 
-(define (iso8601-string->decoded-time string)
-  (let ((v (parse-8601-date/time (string->parser-buffer string))))
+(define (iso8601-string->decoded-time string #!optional start end)
+  (let ((v (*parse-string parser:iso8601-date/time string start end)))
     (if (not v)
        (error:bad-range-argument string 'ISO8601-STRING->DECODED-TIME))
     (vector-ref v 0)))
@@ -409,7 +420,7 @@ USA.
                 (d2 (decoded-time/month dt))
                 "-"
                 (d2 (decoded-time/day dt))
-                "T"
+                (if iso8601-separate-with-t? "T" " ")
                 (d2 (decoded-time/hour dt))
                 ":"
                 (d2 (decoded-time/minute dt))
@@ -423,6 +434,8 @@ USA.
                            zone))
                       ""))))
 
+(define iso8601-separate-with-t? #t)
+
 (define (universal-time->local-iso8601-string time)
   (decoded-time->iso8601-string (universal-time->local-decoded-time time)))
 
@@ -441,7 +454,7 @@ USA.
 (define (iso8601-string->file-time string)
   (decoded-time->file-time (iso8601-string->decoded-time string)))
 \f
-(define parse-8601-date/time
+(define parser:iso8601-date/time
   (*parser
    (encapsulate
        (lambda (v)
index d4b5eaa7c8158562cdc596445f3e67a1038305bd..62e9b3176f8755e416f18cecccdc450462bee5ac 100644 (file)
@@ -1,6 +1,6 @@
 #| -*-Scheme-*-
 
-$Id: runtime.pkg,v 14.660 2008/08/24 07:20:11 cph Exp $
+$Id: runtime.pkg,v 14.661 2008/08/25 08:37:35 cph Exp $
 
 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
     1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
@@ -1254,6 +1254,7 @@ USA.
          day-of-week/short-string
          decode-universal-time
          decoded-time->ctime-string
+         decoded-time->http-string
          decoded-time->iso8601-string
          decoded-time->string
          decoded-time->universal-time
@@ -1274,6 +1275,7 @@ USA.
          file-time->global-ctime-string
          file-time->global-iso8601-string
          file-time->global-time-string
+         file-time->http-string
          file-time->local-ctime-string
          file-time->local-iso8601-string
          file-time->local-time-string
@@ -1281,6 +1283,7 @@ USA.
          get-decoded-time
          get-universal-time
          global-decoded-time
+         iso8601-separate-with-t?
          iso8601-string->decoded-time
          iso8601-string->file-time
          iso8601-string->universal-time
@@ -1289,6 +1292,7 @@ USA.
          month/long-string
          month/max-days
          month/short-string
+         parser:iso8601-date/time
          string->day-of-week
          string->decoded-time
          string->file-time
@@ -1301,6 +1305,7 @@ USA.
          universal-time->global-decoded-time
          universal-time->global-iso8601-string
          universal-time->global-time-string
+         universal-time->http-string
          universal-time->local-ctime-string
          universal-time->local-decoded-time
          universal-time->local-iso8601-string