Skip to content

Instantly share code, notes, and snippets.

@mischa
Created December 23, 2008 09:49
Show Gist options
  • Save mischa/39295 to your computer and use it in GitHub Desktop.
Save mischa/39295 to your computer and use it in GitHub Desktop.
(define-struct time (hours minutes seconds))
(define (time-point hours minutes seconds)
(make-time hours minutes seconds))
(define (time-diff t1 t2)
(cond
[(> (seconds t1) (seconds t2)) ((- one-day (seconds t1)) + (seconds t2))]
[else (- (seconds t2) (seconds t1))]))
(define (seconds time)
(+
(* (time-hours time) 3600)
(* (time-minutes time) 60)
(time-seconds time)))
(define one-day (* 24 3600))
(test-equal? "time-diff" (time-diff (time-point 1 2 3) (time-point 4 5 6)) 10983)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment