unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
From: Zefram <zefram@fysh.org>
To: 26163@debbugs.gnu.org
Subject: bug#26163: time-difference doesn't detect error of differing time types
Date: Wed, 19 Apr 2017 19:12:08 +0100	[thread overview]
Message-ID: <20170419181208.GA912@fysh.org> (raw)
In-Reply-To: <20170318222336.GJ6518@fysh.org>

[-- Attachment #1: Type: text/plain, Size: 25 bytes --]

Patch attached.

-zefram

[-- Attachment #2: 0001-signal-error-of-time-difference-on-differing-types.patch --]
[-- Type: text/x-diff, Size: 1462 bytes --]

From 6f9d9b355233b578eb3ce13549c8fdc9d7fb8364 Mon Sep 17 00:00:00 2001
From: Zefram <zefram@fysh.org>
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


  reply	other threads:[~2017-04-19 18:12 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-18 22:23 bug#26163: time-difference doesn't detect error of differing time types Zefram
2017-04-19 18:12 ` Zefram [this message]
2018-10-21 23:45 ` Mark H Weaver

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170419181208.GA912@fysh.org \
    --to=zefram@fysh.org \
    --cc=26163@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).