(module date (seconds->date-list today date-list->seconds datedate-list secs) (let ((t (seconds->utc-time secs))) (list (+ 1900 (vector-ref t 5)) (add1 (vector-ref t 4)) (vector-ref t 3)))) (define (today) (seconds->date-list (current-seconds))) (define (date-list->seconds d) (let ((t (make-vector 10 0))) (set! (vector-ref t 5) (- (first d) 1900)) (set! (vector-ref t 4) (sub1 (second d))) (set! (vector-ref t 3) (third d)) (utc-time->seconds t))) (define (date m 1) (+ (if (and (> m 2) (leap-year? A)) 1 0) (sub1 (apply + (take (cdr days-in-month-list) (sub1 m)))))) (else -1)))) ;; The gauss method reorders the weekdays, starting at sunday (0) ;; We however want the week to start on monday, hence the renumbering (let ((dow (modulo (+ first-day d month-days) 7))) (if (< (sub1 dow) 0) 6 (sub1 dow))))) ;; Ben Daglish's simple method, see http://www.ben-daglish.net/moon.shtml ;; Returns the phase day (0 to 29, where 0=new moon, 15=full etc.) for ;; the selected date. #;(define (moon-phase date) (let ((lunar-phase 2551443) (new-moon 588900000) (date (time->milliseconds (date->time (date-subtract-duration (make-date 0 0 0 0 day month year) (make-duration #:months 1)))))) (inexact->exact (add1 (floor (/ (modulo (/ (- date new-moon) 1000) lunar-phase) (* 24 3600))))))) ) ;; Module