| Deutsch English Français Italiano |
|
<viihpg$2p17e$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: saito <saitology9@gmail.com>
Newsgroups: comp.lang.tcl
Subject: Re: Seeking help with a time calculation
Date: Sun, 1 Dec 2024 15:43:28 -0500
Organization: A noiseless patient Spider
Lines: 41
Message-ID: <viihpg$2p17e$1@dont-email.me>
References: <vicsj1$13bmu$1@news.xmission.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 01 Dec 2024 21:43:28 +0100 (CET)
Injection-Info: dont-email.me; posting-host="dbdc161aa31b84fe3206294ac11475cc";
logging-data="2917614"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/MSxc0m8DXkPUoTxeh4Rse"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:L5Wry5UzHdAd+3yxneCF+WylkO8=
Content-Language: en-US
In-Reply-To: <vicsj1$13bmu$1@news.xmission.com>
Bytes: 2224
On 11/29/2024 12:10 PM, Kenny McCormack wrote:
> Platform is Linux.
>
> In an Expect script, I want to calculate the number of seconds until the
> next "X minutes after the hour". E.g., if X is 37 and the current time is
> 15:30:30, then the result I seek would be: 390. If X is 37, and the
> current time is 15:50, then the result would be: 2820.
>
> It's the number of seconds I have to wait (sleep) until that time arrives.
>
> I have a method in AWK, which I can (and do) call from my Expect script,
> but I am curious if there is a (simple) native Tcl way to do it.
I think this does the calculation you want. There is an interesting
"octal" problem left as an exercise :-)
proc wait_how_long {x} {
set now [clock seconds]
set mins [clock format $now -format "%M"]
set secs [clock format $now -format "%S"]
if {$mins == $x} {
# in the minute requested
set wait 0
} elseif {$mins < $x} {
# minute has passed
# add one hour
set wait [expr {($x - $mins - 1) * 60 + (60 - $secs)}]
} else {
# some minutes ahead, within the same hour
set mindiff [expr {(60 - $mins - 1) + $x}]
set wait [expr {$mindiff * 60 + (60 - $secs)}]
}
return $wait
}