unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
* bug#26163: time-difference doesn't detect error of differing time types
@ 2017-03-18 22:23 Zefram
  2017-04-19 18:12 ` Zefram
  2018-10-21 23:45 ` Mark H Weaver
  0 siblings, 2 replies; 3+ messages in thread
From: Zefram @ 2017-03-18 22:23 UTC (permalink / raw)
  To: 26163

scheme@(guile-user)> (use-modules (srfi srfi-19))
scheme@(guile-user)> (time-difference (make-time time-tai 0 1) (make-time time-utc 0 1))
$1 = #<time type: time-duration nanosecond: 0 second: 0>

SRFI-19 is explicit that it "is an error" if the arguments to
time-difference are of different time types, and correspondingly the
Guile documentation says the arguments "must be" of the same type.
It would be very easy for time-difference to detect and signal this error.
It's not absolutely a bug that it currently doesn't, but it would be a
useful improvement if it did.

-zefram





^ permalink raw reply	[flat|nested] 3+ messages in thread

* bug#26163: time-difference doesn't detect error of differing time types
  2017-03-18 22:23 bug#26163: time-difference doesn't detect error of differing time types Zefram
@ 2017-04-19 18:12 ` Zefram
  2018-10-21 23:45 ` Mark H Weaver
  1 sibling, 0 replies; 3+ messages in thread
From: Zefram @ 2017-04-19 18:12 UTC (permalink / raw)
  To: 26163

[-- 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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* bug#26163: time-difference doesn't detect error of differing time types
  2017-03-18 22:23 bug#26163: time-difference doesn't detect error of differing time types Zefram
  2017-04-19 18:12 ` Zefram
@ 2018-10-21 23:45 ` Mark H Weaver
  1 sibling, 0 replies; 3+ messages in thread
From: Mark H Weaver @ 2018-10-21 23:45 UTC (permalink / raw)
  To: Zefram; +Cc: 26163-done

Zefram <zefram@fysh.org> writes:

> scheme@(guile-user)> (use-modules (srfi srfi-19))
> scheme@(guile-user)> (time-difference (make-time time-tai 0 1) (make-time time-utc 0 1))
> $1 = #<time type: time-duration nanosecond: 0 second: 0>
>
> SRFI-19 is explicit that it "is an error" if the arguments to
> time-difference are of different time types, and correspondingly the
> Guile documentation says the arguments "must be" of the same type.
> It would be very easy for time-difference to detect and signal this error.
> It's not absolutely a bug that it currently doesn't, but it would be a
> useful improvement if it did.

Agreed.  Fixed in commit c9d903b6e4f8cc1d8382b20a2f0502c4ce8ffe0a on the
stable-2.2 branch.  I'm closing this bug, but feel free to reopen if
appropriate.

     Thanks!
       Mark





^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-10-21 23:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-18 22:23 bug#26163: time-difference doesn't detect error of differing time types Zefram
2017-04-19 18:12 ` Zefram
2018-10-21 23:45 ` Mark H Weaver

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).