/usr/lib/s9fes/time-to-unix-time.scm is in scheme9 2010.11.13-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | ; Scheme 9 from Empty Space, Function Library
; By Nils M Holm, 2009,2010
; See the LICENSE file of the S9fES package for terms of use
;
; (time->unix-time time-list) ==> integer | #f
;
; TIME->UNIX-TIME converts TIME-LIST (see UNIX-TIME->TIME) to the
; number of seconds since the Unix epoch. It returns #F if TIME-LIST
; is not a proper time list.
;
; Example: (time->unix-time '(6 2010 4 25 7 1 19)) ==> 1272178879
(load-from-library "leap-yearp.scm")
(load-from-library "proper-timep.scm")
(define (time->unix-time t)
(let* ((leap-year? leap-year?)
(proper-time? proper-time?)
(days/mon (vector 31 28 31 30 31 30 31 31 30 31 30 31))
(sec/hour (* 60 60))
(sec/day (* 24 sec/hour))
(sec/year (* 365 sec/day))
(leap-years-until
(lambda (x)
(+ (quotient x 4)
(- (quotient x 100))
(quotient x 400)))))
(if (and (list? t)
(= (length t) 7)
(number? (cadr t))
(leap-year? (cadr t)))
(vector-set! days/mon 1 29))
(and (proper-time? t)
(let ((leap-days (- (leap-years-until (- (list-ref t 1) 1))
(leap-years-until 1970))))
(+ (* sec/year (- (list-ref t 1) 1970))
(* sec/day leap-days)
(let loop ((d 0)
(m 1))
(if (< m (list-ref t 2))
(loop (+ d (vector-ref days/mon (- m 1)))
(+ 1 m))
(* d sec/day)))
(* sec/day (- (list-ref t 3) 1))
(* sec/hour (list-ref t 4))
(* 60 (list-ref t 5))
(list-ref t 6))))))
|