From: Chris Hanson Date: Tue, 23 May 2000 21:48:53 +0000 (+0000) Subject: Do pivoting when deciding what a two-digit year means. I can't X-Git-Tag: 20090517-FFI~3691 X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=9ac3e0dbb04a32e20c8dbee9fa94e98b9395b913;p=mit-scheme.git Do pivoting when deciding what a two-digit year means. I can't believe that some programs still generate these strings! --- diff --git a/v7/src/runtime/datime.scm b/v7/src/runtime/datime.scm index cc3a083d6..ccf21757f 100644 --- a/v7/src/runtime/datime.scm +++ b/v7/src/runtime/datime.scm @@ -1,6 +1,6 @@ #| -*-Scheme-*- -$Id: datime.scm,v 14.28 2000/05/15 18:15:36 cph Exp $ +$Id: datime.scm,v 14.29 2000/05/23 21:48:53 cph Exp $ Copyright (c) 1988-2000 Massachusetts Institute of Technology @@ -253,11 +253,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. (string->number (car time)) (string->number (list-ref tokens 0)) (string->month (list-ref tokens 1)) - (let ((n (string->number (list-ref tokens 2)))) - (and (exact-nonnegative-integer? n) - (if (< n 100) - (+ 1900 n) - n))) + (string->year (list-ref tokens 2)) (string->time-zone (list-ref tokens 4))))))) (define (string->universal-time string) @@ -343,12 +339,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. (string->number (car time)) (string->number (list-ref tokens 2)) (string->month (list-ref tokens 1)) - (let ((n (string->number (list-ref tokens 4)))) - (if (not (exact-nonnegative-integer? n)) - (lose)) - (if (< n 100) - (+ 1900 n) - n)) + (string->year (list-ref tokens 4)) zone))))) (define (universal-time->local-ctime-string time) @@ -434,6 +425,14 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ((string-ci=? string (vector-ref string-vector index)) index) (else (loop (fix:+ index 1))))))) +(define (string->year string) + (let ((n (string->number string))) + (if (not (exact-nonnegative-integer? n)) + (error:bad-range-argument string 'STRING->YEAR)) + (cond ((< n 38) (+ 2000 n)) + ((< n 100) (+ 1900 n)) + (else n)))) + ;; Upwards compatibility (define decode-universal-time universal-time->local-decoded-time) (define encode-universal-time decoded-time->universal-time)