#lang scheme/base
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; DATE-TZ.plt - provides time-zone-based date calculations
;; Bonzai Lab, LLC.  All rights reserved.
;; released under LGPL.
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; - contains the basic structure definitions for tz computation
;; yc 10/2/2009 - first version

(require srfi/19)

(define-struct zone-span (offset rule format until) #:prefab)

(define-struct *zone-span (offset rule format) #:prefab)

(define-struct rule (from to type month date time offset format) #:prefab)

(define-struct span (bound std dst year) #:prefab) 

(define (make-span* bound std dst)
  (make-span bound std dst (if (equal? bound -inf.0) bound
                               (date-year bound))))

(define-struct tz (spans rules min) #:prefab)

(define-struct *date (year month day hour minute second tz-offset) #:prefab)

(define TZ-YEAR-MAX 2039)

(define TZ-YEAR-MIN 1800)

(define (*date->date d)
  (make-date 0
             (*date-second d)
             (*date-minute d)
             (*date-hour d)
             (*date-day d)
             (*date-month d)
             (*date-year d)
             (*date-tz-offset d)))

(define (date->*date d)
  (make-*date (date-year d)
              (date-month d)
              (date-day d)
              (date-hour d)
              (date-minute d)
              (date-second d)
              (date-zone-offset d)))

(provide (struct-out tz) 
         (struct-out rule) 
         (struct-out span) 
         (struct-out zone-span)
         (struct-out *zone-span)
         (struct-out *date)