| View previous topic :: View next topic |
| Author |
Message |
Luminous Op
Joined: 12 Feb 2010 Posts: 146
|
Posted: Tue Mar 30, 2010 4:09 pm Post subject: Regarding time and clock scan/seconds |
|
|
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?t=12507&highlight=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: |
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. |
|
| Back to top |
|
 |
Luminous Op
Joined: 12 Feb 2010 Posts: 146
|
Posted: Tue Mar 30, 2010 8:28 pm Post subject: |
|
|
Worth noting that paste.tcl-help.net reports no errors on this:
| Code: |
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? |
|
| Back to top |
|
 |
TCL_no_TK Owner

Joined: 25 Aug 2006 Posts: 509 Location: England, Yorkshire
|
Posted: Wed Mar 31, 2010 10:44 am Post subject: |
|
|
http://tcl.tk/man/tcl8.5/TclCmd/clock.htm#M10 | Quote: | % 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
% |  _________________ TCL the misunderstood |
|
| Back to top |
|
 |
speechles Revered One

Joined: 26 Aug 2006 Posts: 1398 Location: emerald triangle, california (coastal redwoods)
|
Posted: Wed Mar 31, 2010 4:47 pm Post subject: |
|
|
| Quote: | [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..
| Code: | 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)}]]"
} |
_________________ speechles' eggdrop tcl archive |
|
| Back to top |
|
 |
Luminous Op
Joined: 12 Feb 2010 Posts: 146
|
Posted: Mon Apr 05, 2010 7:57 pm Post subject: |
|
|
| Ah, thank you! I don't actually need this bind anymore, but its still nice to know how to do for future use. |
|
| Back to top |
|
 |
|