From b3f47e937796229e08de7efb1faa50e24a3ec91a Mon Sep 17 00:00:00 2001 From: Chris Hanson Date: Mon, 25 Aug 2008 08:37:35 +0000 Subject: [PATCH] Add support for generating the HTTP date strings: required use of "GMT" time zone marker. Also export the parser for iso8601 time. --- v7/src/runtime/datime.scm | 43 +++++++++++++++++++++++++------------- v7/src/runtime/runtime.pkg | 7 ++++++- 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/v7/src/runtime/datime.scm b/v7/src/runtime/datime.scm index 8de63ac7d..eaae4a27d 100644 --- a/v7/src/runtime/datime.scm +++ b/v7/src/runtime/datime.scm @@ -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))) + ""))))) (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))) -(define parse-8601-date/time +(define parser:iso8601-date/time (*parser (encapsulate (lambda (v) diff --git a/v7/src/runtime/runtime.pkg b/v7/src/runtime/runtime.pkg index d4b5eaa7c..62e9b3176 100644 --- a/v7/src/runtime/runtime.pkg +++ b/v7/src/runtime/runtime.pkg @@ -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 -- 2.25.1