Subject: bug#26163: time-difference doesn't detect error of differing time types

From: Zefram <[email-masked]>
Date: Wed, 19 Apr 2017 19:12:08 +0100

Patch attached.

-zefram
>From 6f9d9b355233b578eb3ce13549c8fdc9d7fb8364 Mon Sep 17 00:00:00 2001
From: Zefram <[email-masked]>
Date: Wed, 19 Apr 2017 19:02:13 +0100
Subject: [PATCH] signal error of time-difference on differing types

It is an error to apply SRFI-19's time-difference to time structures of
differing time types.  Detect and signal the error.
---
 module/srfi/srfi-19.scm | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/module/srfi/srfi-19.scm b/module/srfi/srfi-19.scm
index c6a55a2..8da711f 100644
--- a/module/srfi/srfi-19.scm
+++ b/module/srfi/srfi-19.scm
@@ -413,12 +413,14 @@
 ;; -- Time arithmetic
 
 (define (time-difference! time1 time2)
-  (let ((sec-diff (- (time-second time1) (time-second time2)))
-        (nsec-diff (- (time-nanosecond time1) (time-nanosecond time2))))
-    (set-time-type! time1 time-duration)
-    (set-time-second! time1 sec-diff)
-    (set-time-nanosecond! time1 nsec-diff)
-    (time-normalize! time1)))
+  (if (not (eq? (time-type time1) (time-type time2)))
+      (time-error 'time-difference 'incompatible-time-types time2)
+      (let ((sec-diff (- (time-second time1) (time-second time2)))
+	    (nsec-diff (- (time-nanosecond time1) (time-nanosecond time2))))
+	(set-time-type! time1 time-duration)
+	(set-time-second! time1 sec-diff)
+	(set-time-nanosecond! time1 nsec-diff)
+	(time-normalize! time1))))
 
 (define (time-difference time1 time2)
   (let ((result (copy-time time1)))
-- 
2.1.4