Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

BOFH excuse #307: emissions from GSM-phones


comp / comp.lang.tcl / Seeking help with a time calculation

SubjectAuthor
* Seeking help with a time calculationKenny McCormack
+- Re: Seeking help with a time calculationGerald Lester
`- Re: Seeking help with a time calculationsaito

1
Subject: Seeking help with a time calculation
From: Kenny McCormack
Newsgroups: comp.lang.tcl
Organization: The official candy of the new Millennium
Date: Fri, 29 Nov 2024 17:10 UTC
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!news.hispagatos.org!news.samoylyk.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gazelle@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.lang.tcl
Subject: Seeking help with a time calculation
Date: Fri, 29 Nov 2024 17:10:57 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <vicsj1$13bmu$1@news.xmission.com>
Injection-Date: Fri, 29 Nov 2024 17:10:57 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="1158878"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
View all headers

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.
--
Men rarely (if ever) manage to dream up a God superior to themselves.
Most Gods have the manners and morals of a spoiled child.

Subject: Re: Seeking help with a time calculation
From: Gerald Lester
Newsgroups: comp.lang.tcl
Organization: fastusenet - www.fastusenet.org
Date: Sun, 1 Dec 2024 03:47 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!weretis.net!feeder8.news.weretis.net!ecngs!feeder2.ecngs.de!144.76.237.92.MISMATCH!3.eu.feeder.erje.net!feeder.erje.net!feeder2.feed.ams11.usenet.farm!feed.usenet.farm!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!feeder.usenetexpress.com!tr2.iad1.usenetexpress.com!news-out.netnews.com!s1-3.netnews.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx18.iad.POSTED!not-for-mail
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
Subject: Re: Seeking help with a time calculation
Newsgroups: comp.lang.tcl
References: <vicsj1$13bmu$1@news.xmission.com>
Content-Language: en-US
From: Gerald.Lester@gmail.com (Gerald Lester)
In-Reply-To: <vicsj1$13bmu$1@news.xmission.com>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 17
Message-ID: <h%Q2P.21880$tKZd.7365@fx18.iad>
X-Complaints-To: abuse@fastusenet.org
NNTP-Posting-Date: Sun, 01 Dec 2024 03:47:25 UTC
Organization: fastusenet - www.fastusenet.org
Date: Sat, 30 Nov 2024 21:47:24 -0600
X-Received-Bytes: 1356
View all headers

On 11/29/24 11:10, 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.

The [clock add], [clock seconds], and maybe the [clock format] commands
are your friends.

Subject: Re: Seeking help with a time calculation
From: saito
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Sun, 1 Dec 2024 20:43 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: saitology9@gmail.com (saito)
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>
View all headers

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
}

1

rocksolid light 0.9.8
clearnet tor