This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

gettime error

Old posts that have not been replied to for several years.
Locked
N
NewzUK
Master
Posts: 200
Joined: Mon Nov 18, 2002 3:10 am
Location: Auckland, New Zealand
Contact:

gettime error

Post by NewzUK »

Hi there

I have this proc which I use in a couple of scripts to display the time in various timezones by inserting:

[gettime -5]
for example for USET. However at a few times in the day I get this error, and the message is not displayed:

[09:00] Tcl error [put:hour]: expected integer but got "09" (looks like invalid octal number)

The proc is:

proc gettime { offset } {
set hour [clock format [clock seconds] -format "%H"]
set therest [clock format [clock seconds] -format "%M"]
set time_ret [expr $hour + $offset]
if {[expr $time_ret > 23]} { set time_ret [expr $time_ret - 24] }
if {[expr $time_ret < 0]} { set time_ret [expr $time_ret + 24] }
return $time_ret:$therest
}

It works mostly, but at 08:00 08:30 09:00 and 21:00 GMT it seems to produce this error.

If anyone can spot anything wrong or other help I'd appreciate it...
#Newsroom - Where News & Markets Connect
http://www.inewsroom.net
#Newsroom on irc.othernet.org
User avatar
strikelight
Owner
Posts: 708
Joined: Mon Oct 07, 2002 10:39 am
Contact:

Re: gettime error

Post by strikelight »

NewzBoy wrote:Hi there

I have this proc which I use in a couple of scripts to display the time in various timezones by inserting:

[gettime -5]
for example for USET. However at a few times in the day I get this error, and the message is not displayed:

[09:00] Tcl error [put:hour]: expected integer but got "09" (looks like invalid octal number)

The proc is:

proc gettime { offset } {
set hour [clock format [clock seconds] -format "%H"]
set therest [clock format [clock seconds] -format "%M"]
set time_ret [expr $hour + $offset]
if {[expr $time_ret > 23]} { set time_ret [expr $time_ret - 24] }
if {[expr $time_ret < 0]} { set time_ret [expr $time_ret + 24] }
return $time_ret:$therest
}

It works mostly, but at 08:00 08:30 09:00 and 21:00 GMT it seems to produce this error.

If anyone can spot anything wrong or other help I'd appreciate it...

Code: Select all

set hour [string trimleft [clock format [clock seconds] -format "%H"] 0]
Also, you don't need to add command substitution to evaluate the range of time_ret ...

ie.

Code: Select all

if {$time_ret > 23} { ... }
and
if {$time_ret < 0} { ...}
will suffice
N
NewzUK
Master
Posts: 200
Joined: Mon Nov 18, 2002 3:10 am
Location: Auckland, New Zealand
Contact:

Post by NewzUK »

thanks strikelight - I made those changes, but unfortunatly 08:00 GMT just came and went and I got the same error:

[08:00] Tcl error [put:hour]: expected integer but got "08" (looks like invalid octal number)

:-?
#Newsroom - Where News & Markets Connect
http://www.inewsroom.net
#Newsroom on irc.othernet.org
User avatar
strikelight
Owner
Posts: 708
Joined: Mon Oct 07, 2002 10:39 am
Contact:

Post by strikelight »

When I looked at the code you pasted, I had (incorrectly) assumed you has pasted the corresponding code related to the error. However, I was in error. You have not shown us the put:hour procedure.
N
NewzUK
Master
Posts: 200
Joined: Mon Nov 18, 2002 3:10 am
Location: Auckland, New Zealand
Contact:

Post by NewzUK »

This is one of them - it runs the BBC News script. There's another one I have called put:half (for a half hourly message) which just sends a message to the channel and this also gets the error message.

bind time - "00 * * * *" put:hour
proc put:hour { min hour day month year } {
putserv "PRIVMSG #NewsRoom :12,12 0,4 >Newsroom LIVE 7,7 0,12 World Headlines @ [gettime -18]ET / [gettime -13]GMT "
bbc:parse "http://news.bbc.co.uk/2/low.html" 1 #NewsRoom #NewsRoom
}

Thanks.
#Newsroom - Where News & Markets Connect
http://www.inewsroom.net
#Newsroom on irc.othernet.org
User avatar
strikelight
Owner
Posts: 708
Joined: Mon Oct 07, 2002 10:39 am
Contact:

Post by strikelight »

Welp, then you didn't change your "set hour" line in your gettime proc, with the one involving the "string trimleft" that I gave you.
N
NewzUK
Master
Posts: 200
Joined: Mon Nov 18, 2002 3:10 am
Location: Auckland, New Zealand
Contact:

Post by NewzUK »

yes I did - and it still gives the error.

oh well - looks like it's in the too hard basket!
#Newsroom - Where News & Markets Connect
http://www.inewsroom.net
#Newsroom on irc.othernet.org
User avatar
strikelight
Owner
Posts: 708
Joined: Mon Oct 07, 2002 10:39 am
Contact:

Post by strikelight »

Prove you have done what you said, by both showing your newly altered code, and also issue a '.tcl set errorInfo' on your partyline, after the error is generated.
N
NewzUK
Master
Posts: 200
Joined: Mon Nov 18, 2002 3:10 am
Location: Auckland, New Zealand
Contact:

Post by NewzUK »

excuse me - 'prove it'?

I said I did it, and it didn't work.

I don't need it that badly that I'll put up with some kind of arrogant inquisition.

Thanks anyway.
#Newsroom - Where News & Markets Connect
http://www.inewsroom.net
#Newsroom on irc.othernet.org
User avatar
strikelight
Owner
Posts: 708
Joined: Mon Oct 07, 2002 10:39 am
Contact:

Post by strikelight »

If you had done what you said you had done, you would have nothing to hide. But apparently, you are too proud to admit you faltered in doing something you said, when you didn't. That is what anyone can conclude, from the lack of information provided on your behalf.
N
NewzUK
Master
Posts: 200
Joined: Mon Nov 18, 2002 3:10 am
Location: Auckland, New Zealand
Contact:

Post by NewzUK »

LOL I did do what you suggested - why would I not if I was seeking to solve my problem? The reason I didn't post the error again is because it was exactly the same as before so there was no need to 'prove' anything.

Your help did not fix the problem - and now I've just seen it produces the error more than it did before, so your code failed and made the problem worse. So have reverted back to original version.

No pride here - just the facts!

There's no need to act all superior to those of us who are't scripting experts - this is supposed to be a 'help' forum - not to use your knowledge (questionable in this case) to try to make others feel stupid.
#Newsroom - Where News & Markets Connect
http://www.inewsroom.net
#Newsroom on irc.othernet.org
User avatar
strikelight
Owner
Posts: 708
Joined: Mon Oct 07, 2002 10:39 am
Contact:

Post by strikelight »

Here are the facts... what you were told, works....

Code: Select all

% proc gettime { offset } { 
set hour [string trimleft [clock format 1075708800 -format "%H"] 0]
set therest [clock format 1075708800 -format "%M"] 
set time_ret [expr $hour + $offset] 
if {$time_ret > 23} { set time_ret [expr $time_ret - 24] } 
if {$time_ret < 0} { set time_ret [expr $time_ret + 24] } 
return $time_ret:$therest 
} 
% gettime -18
9:00
% gettime -13
14:00
%
(note: 1075708800 is 08:00 GMT as per your description of where the error occurs)
So there are the facts.. the conclusion: you didn't do what you were told, thus you didn't want help from the get go.
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

why do all that weird stuff?

Post by user »

Code: Select all

proc gettime {{offset 0}} {
	clock format [expr {[clock seconds]+($offset*3600)}] -format %H:%M
}
Have you ever read "The Manual"?
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

NewzBoy.

The code strikelight posted should and does work.

It is a well known workaround to other problems related to the time bind.

You apear to be using the time bind, and it would also apear you are failing to post the whole of your put:hour code.

How do we know this?

Because of this line.

Code: Select all

bind time - "00 * * * *" put:hour 
This would run once and hour on the hour. However, you have been sugesting that your code runs at 08:30. Which is pretty must 1/2 an hour too late (or early).

Another note, you should be quoting your string in full if your are returning more than one thing. Keeps things safe.

Code: Select all

return "${time_ret}:${therest}"
N
NewzUK
Master
Posts: 200
Joined: Mon Nov 18, 2002 3:10 am
Location: Auckland, New Zealand
Contact:

Post by NewzUK »

I just copied and pasted the above script into the bot, and my half-hour message said the time of the previous top of the hour (said 6:00ET when should have been 6:30)

Just to confirm I have hourly and half hourly msgs...

:cry:
#Newsroom - Where News & Markets Connect
http://www.inewsroom.net
#Newsroom on irc.othernet.org
Locked