Skip to content

Commit

Permalink
Limit seconds+ to take real number as dt
Browse files Browse the repository at this point in the history
We can extend it to take time-duration, but probably it's better
to limit it to SRFI-226 domain.  We have absolute-time if the user
wants to pass time-duration.
  • Loading branch information
shirok committed Nov 28, 2023
1 parent a9397c3 commit a57f003
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
11 changes: 8 additions & 3 deletions doc/corelib.texi
Original file line number Diff line number Diff line change
Expand Up @@ -32114,20 +32114,25 @@ object, it is used as the current time instead of the actual current time.
@end defun

@defun seconds+ time x
[SRFI-226]
[SRFI-226+]
@c EN
Returns a time object that is @var{x} seconds after the given @var{time}.
The type of returned time object is the same as @var{time}.
The argument @var{x} must be a finite real number. If it is negative,
returnd time is before the given time.

This procedure is mainly to write code compatibe to SRFI-226.
For Gauche-specific code, you can use @code{absolute-time} above.

@xref{SRFI-19 Time procedures}, for another way to compute with time
difference by @code{add-duration}/@code{subtract-duration}.
@c JP
与えられた@var{time}より@var{x}秒後を表すtimeオブジェクトを作って返します。
返されるtimeオブジェクトの型は@var{time}と同じです。
@var{x}は有限の実数でなければなりません。@var{x}が負の場合は、
与えられた時間より前の時間が返ります。
@var{x}は有限の実数です。@var{x}が負の場合は、与えられた時間より前の時間が返ります。

この手続きはSRFI-226準拠のコードを書くために用意されています。
Gauche専用のコードなら上の@code{absolute-time}も使えます。

時間の計算には、SRFI-19の@code{add-duration}/@code{subtract-duration}
も使えます。@ref{SRFI-19 Time procedures}を参照してください。
Expand Down
5 changes: 4 additions & 1 deletion src/libsys.scm
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,10 @@
(-> pts tv_sec)
(-> pts tv_nsec)))))))

(define (seconds+ t dt) (absolute-time dt t)) ;SRFI-226 comatibility
(define (seconds+ t dt)
(assume-type t <time>)
(assume-type dt <real>)
(absolute-time dt t)) ;SRFI-226 comatibility

(define-cproc time->seconds (t::<time>) ;SRFI-18
Scm_TimeToSeconds)
Expand Down

0 comments on commit a57f003

Please sign in to comment.