Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Seconds without leading zero

66 views
Skip to first unread message

Cecil Westerhof

unread,
Dec 4, 2017, 7:59:06 AM12/4/17
to
I want something to be done at the start of a minute. So I use:
set currentSeconds [clock seconds]
after [expr 1000 * (60 - [clock format ${currentSeconds} -format %S])]

But this goes wrong when the seconds are 08 or 09. Can I get the
seconds without the leading zero?

--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

jda...@gmail.com

unread,
Dec 4, 2017, 10:31:34 AM12/4/17
to

Try:
after [expr {1000*([clock seconds]%60]}] ...

According to man page TCL time model handles leap seconds by stretching time instead of inserting an extra second.

Might not do what you want if called during zero second.

Dave

Cecil Westerhof

unread,
Dec 4, 2017, 11:44:07 AM12/4/17
to
That works like a charm. Thanks.

It is done in a loop. In zero second it has just be done and I want to
wait a minute, so it does exactly what I want.

Ricardo kozmate.net

unread,
Dec 4, 2017, 4:42:10 PM12/4/17
to
Em 04/12/17 12:46, Cecil Westerhof escreveu:
> this goes wrong when the seconds are 08 or 09

That is because a string with a leading "0" is interpreted as a octal
number, and "08" and "09" are not valid octal numbers.

Dave already gave a good suggestion for your specific problem, but for
the "08"/"09" problem in general you may want to (re)read "Tcl and octal
numbers" at http://wiki.tcl.tk/498

--
{ricardo from kozmate.net}

Ralf Fassel

unread,
Dec 6, 2017, 5:25:47 AM12/6/17
to
* Cecil Westerhof <Ce...@decebal.nl>
| I want something to be done at the start of a minute. So I use:
| set currentSeconds [clock seconds]
| after [expr 1000 * (60 - [clock format ${currentSeconds} -format %S])]

clock format ${currentSeconds} -format %S
09

string trimleft [clock format ${currentSeconds} -format %S] 0
9

HTH
R'

Ralf Fassel

unread,
Dec 6, 2017, 5:26:43 AM12/6/17
to
* Ralf Fassel <ral...@gmx.de>
... and check for the result not being the empty string in case of 00.

R'

Rich

unread,
Dec 6, 2017, 6:03:40 AM12/6/17
to
Or, use scan's %d conversion, which is not bothered by leading zeros.

$ rlwrap tclsh
% set time [clock scan 00:00:00 -format %H:%M:%S]
1512536400
% clock format $time -format %S
00
% expr {1000 * (60 - [scan [clock format $time -format %S] %d z ; set z])}
60000

0 new messages