;;; -*- Mode:Lisp; Readtable:ZL; Package:USER; Base:10; Patch-File:T -*-
;;; Patch file for System version 121.52
;;; Reason:
;;;  Congress broke the time so I had to fix it.  Does anyone know if they broke October also?
;;; Written 6-Apr-87 16:31:12 by naha (Mark Nahabedian) at site LMI Cambridge
;;; while running on Love from band 2
;;; with Experimental System 121.51, Experimental Lambda-Diag 15.0, Experimental ZMail 70.2, Experimental KERMIT 32.0, Experimental Unix-Interface 10.0, Experimental Local-File 72.0, Experimental FILE-Server 21.0, Experimental Tape 13.0, Experimental Site Data Editor 5.0, microcode 1733, SDU Boot Tape 3.13, SDU ROM 102, 121.35.



; From modified file DJ: L.IO1; TIME.LISP#134 at 6-Apr-87 16:31:17
#10R TIME#: 
(COMPILER-LET ((*PACKAGE* (PKG-FIND-PACKAGE "TIME")))
  (COMPILER::PATCH-SOURCE-FILE "SYS: IO1; TIME  "

(defun day-of-week-first-day-of-year (year)
  ;;; Sunday is 0
  (flet ((n-leap-days (year)
	   (setq year (1- year))			; don't count this year yet
	   (let ((year-div-4 (floor year 4))		; extra day every 4,
		 (year-div-100 (- (floor year 100.)))	;   except every 100,
		 (year-div-400 (floor year 400.)))	;     except every 400.
	     (+ year-div-4 year-div-100 year-div-400))))
    (let* ((base-year 1900.)
	   (base-day 1)				; 1900 began on a Monday
	   (leap-days-since-base (- (n-leap-days year) (n-leap-days base-year)))
	   (non-leap-days-since-base (* 365. (- year base-year))))
      (cl:rem (+ base-day non-leap-days-since-base leap-days-since-base)
	      7))))

))

; From modified file DJ: L.IO1; TIME.LISP#134 at 6-Apr-87 16:31:25
#10R TIME#: 
(COMPILER-LET ((*PACKAGE* (PKG-FIND-PACKAGE "TIME")))
  (COMPILER::PATCH-SOURCE-FILE "SYS: IO1; TIME  "

(defun first-sunday-in-april (year)
  (let* ((day-year-started-on (day-of-week-first-day-of-year year))
	 (feb29 (if (leap-year-p year) 1 0))
	 (days-before-april (+ 31 28 feb29 31))
	 (day-of-week-april-first (cl:rem (+ day-year-started-on days-before-april) 7)) )
    (cl:rem (- 7 day-of-week-april-first) 7)))

))

; From modified file DJ: L.IO1; TIME.LISP#134 at 6-Apr-87 16:58:54
#10R TIME#: 
(COMPILER-LET ((*PACKAGE* (PKG-FIND-PACKAGE "TIME")))
  (COMPILER::PATCH-SOURCE-FILE "SYS: IO1; TIME  "

(defun daylight-savings-time-in-usa-p (seconds minutes hours day month year)
  (declare (ignore seconds minutes))
  ;;; remember, HOURS here is allways in standard time.
  (cond ((< month 4) nil)			; before April
	((> month 10) nil)			; after October
	((= month 4)
	 (let ((magic-day (cond ((< year 1987) (last-sunday-in-april year))
				((>= year 1987) (first-sunday-in-april year)))))
	   (cond ((< day magic-day) nil)
		 ((> day magic-day) t)
		 ((>= hours 2) t)
		 (t nil))))
	((= month 10)
	 (let ((magic-day (time:last-sunday-in-october year)))
	   (cond ((< day magic-day) t)
		 ((> day magic-day nil))
		 ((>= hours 1) nil)
		 (t t))))))    

))

; From modified file DJ: L.IO1; TIME.LISP#134 at 6-Apr-87 18:00:21
#10R TIME#: 
(COMPILER-LET ((*PACKAGE* (PKG-FIND-PACKAGE "TIME")))
  (COMPILER::PATCH-SOURCE-FILE "SYS: IO1; TIME  "

(setq *DAYLIGHT-SAVINGS-TIME-P-FUNCTION* 'daylight-savings-time-in-usa-p)

))
