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.

Regarding time and clock scan/seconds

Help for those learning Tcl or writing their own scripts.
Post Reply
L
Luminous
Op
Posts: 146
Joined: Fri Feb 12, 2010 1:00 pm

Regarding time and clock scan/seconds

Post by Luminous »

I need a script that will display, on a public !command, how many hours:mins:secs is left until a specified time. In this case 12:00. However, I need to deduct 1 hour from my time to cover the timezone difference before announcing time before midnight. But I am confused as to what I actually need to use to do this. I was looking at this thread: http://forum.egghelp.org/viewtopic.php? ... light=zone which is where I learned about clock scan/seconds, but I am unsure of how to use these to do what I need.

This is what i have so far. Have not tested it, as I am not sure I even did the bind properly:

Code: Select all

bind pub * !time time:left
 proc time:left {nick host hand chan} {
   set tartime [clock scan "00:00:00"]
   set mytime [clock scan "%T"
   set offset [duration [expr $mytime - 3600]] ; #I assume I would subtract an hour by seconds
   set difftime [duration [expr $offset -  $tartime]
       if {$offset != $tartime} {
          putserv "PRIVMSG $nick :Time left until midnight is $difftime"
        }
}
Please advise, thanks.
L
Luminous
Op
Posts: 146
Joined: Fri Feb 12, 2010 1:00 pm

Post by Luminous »

Worth noting that paste.tcl-help.net reports no errors on this:

Code: Select all

bind pub * !time time:left
proc time:left {nick host hand chan text} {
    set tartime [clock scan "00:00:00"]
    set mytime [clock scan "%T"]
    set offset [duration [expr {$mytime - 3600}]]
    set difftime [duration [expr {$offset -  $tartime}]]
    if {$offset != $tartime} {
	putserv "PRIVMSG $nick :Time left until tomorrow is $difftime"
    }
}
But I get an error in partyline when I load the command "Tcl error [time:left]: unable to convert date-time string "%T": syntax error (characters 0-0)"

Do I need to specify the format?
User avatar
TCL_no_TK
Owner
Posts: 509
Joined: Fri Aug 25, 2006 7:05 pm
Location: England, Yorkshire

Post by TCL_no_TK »

http://tcl.tk/man/tcl8.5/TclCmd/clock.htm#M10
% clock scan "Tomorrow"
1270076400
% clock format [clock scan "Tomorrow"]
Thu Apr 01 00:00:00 BST 2010
% clock scan "24 hours"
1270132959
% clock format [clock scan "24 hours"]
Thu Apr 01 15:42:48 BST 2010
% clock format [clock scan "23 hours"]
Thu Apr 01 14:43:05 BST 2010
%
:roll:
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

[12:45pm] <speechles> .tcl set myoffset 1
[12:45pm] <sp33chy> Tcl: 1
[12:45pm] <speechles> .tcl set timeLeftTilMidnigt [duration [expr {[clock scan "tomorrow 00:00"] - [clock seconds] - ($myoffset * 3600)}]]
[12:45pm] <sp33chy> Tcl: 10 hours 14 minutes 10 seconds
...
[12:49pm] <speechles> .tcl set myoffset 0
[12:49pm] <sp33chy> Tcl: 0
[12:49pm] <speechles> .tcl set timeLeftTilMidnigt [duration [expr {[clock scan "tomorrow 00:00"] - [clock seconds] - ($myoffset * 3600)}]]
[12:49pm] <sp33chy> Tcl: 11 hours 10 minutes 6 seconds
Pretty simple.. :lol:

Code: Select all

set myoffset 1
bind pub - !time time:left
proc time:left {nick host hand chan text} {
   putserv "PRIVMSG $nick :Time left until midnight is: [duration [expr {[clock scan "tomorrow 00:00"] - [clock seconds] - ($::myoffset * 3600)}]]"
}
L
Luminous
Op
Posts: 146
Joined: Fri Feb 12, 2010 1:00 pm

Post by Luminous »

Ah, thank you! I don't actually need this bind anymore, but its still nice to know how to do for future use.
Post Reply