From: Chris Hanson Date: Sat, 22 Apr 1995 23:37:23 +0000 (+0000) Subject: Implement some rudimentary time-zone code so that we can produce X-Git-Tag: 20090517-FFI~6417 X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=d0e8f79fef829e3e24adcecc425cf71336e870a5;p=mit-scheme.git Implement some rudimentary time-zone code so that we can produce reasonably accurate time zones in RFC-822 dates. --- diff --git a/v7/src/runtime/datime.scm b/v7/src/runtime/datime.scm index 6b6b54da3..d68c96c3a 100644 --- a/v7/src/runtime/datime.scm +++ b/v7/src/runtime/datime.scm @@ -1,6 +1,6 @@ #| -*-Scheme-*- -$Id: datime.scm,v 14.7 1995/04/15 06:56:27 cph Exp $ +$Id: datime.scm,v 14.8 1995/04/22 23:37:09 cph Exp $ Copyright (c) 1988-95 Massachusetts Institute of Technology @@ -138,4 +138,35 @@ MIT in each case. |# (if (< second 10) ":0" ":") (number->string second) " " - (if (< hour 12) "AM" "PM")))) \ No newline at end of file + (if (< hour 12) "AM" "PM")))) + +(define (time-zone? object) + (and (number? object) + (exact? object) + (<= -24 object 24) + (integer? (* 3600 object)))) + +(define (time-zone->string tz) + (if (not (time-zone? tz)) + (error:wrong-type-argument tz "time zone" 'TIME-ZONE->STRING)) + (let ((minutes (round (* 60 (- tz))))) + (let ((qr (integer-divide (abs minutes) 60))) + (string-append (if (< minutes 0) "-" "+") + (string-pad-left (integer-divide-quotient qr) 2 #\0) + (string-pad-left (integer-divide-remainder qr) 2 #\0))))) + +(define (decoded-time/daylight-savings-time? dt) + ;; In current implementation, DAY-OF-WEEK field might be missing, so + ;; there this will return wrong answer near the changeovers. + (let ((month (decoded-time/month dt))) + (cond ((= 4 month) + (or (> (decoded-time/day dt) 7) + (not (eqv? (decoded-time/day-of-week dt) 6)) + (> (decode-time/hour dt) 1))) + ((= 10 month) + (or (< (decoded-time/day dt) 25) + (not (eqv? (decoded-time/day-of-week dt) 6)) + ;; Since DT is a local time, it's impossible to + ;; tell whether we're in the overlapped hour. + (< (decode-time/hour dt) 3))) + (else (<= 5 month 9))))) \ No newline at end of file diff --git a/v7/src/runtime/runtime.pkg b/v7/src/runtime/runtime.pkg index 568a3b353..fda3995f5 100644 --- a/v7/src/runtime/runtime.pkg +++ b/v7/src/runtime/runtime.pkg @@ -1,6 +1,6 @@ #| -*-Scheme-*- -$Id: runtime.pkg,v 14.252 1995/04/15 06:10:04 cph Exp $ +$Id: runtime.pkg,v 14.253 1995/04/22 23:37:23 cph Exp $ Copyright (c) 1988-95 Massachusetts Institute of Technology @@ -375,6 +375,7 @@ MIT in each case. |# decoded-time/date-string decoded-time/day decoded-time/day-of-week + decoded-time/daylight-savings-time? decoded-time/hour decoded-time/minute decoded-time/month @@ -387,7 +388,9 @@ MIT in each case. |# make-decoded-time month/long-string month/max-days - month/short-string)) + month/short-string + time-zone->string + time-zone?)) (define-package (runtime debugger) (files "debug")