egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Regarding time and clock scan/seconds

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
Luminous
Op


Joined: 12 Feb 2010
Posts: 146

PostPosted: Tue Mar 30, 2010 4:09 pm    Post subject: Regarding time and clock scan/seconds Reply with quote

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
View user's profile Send private message
Luminous
Op


Joined: 12 Feb 2010
Posts: 146

PostPosted: Tue Mar 30, 2010 8:28 pm    Post subject: Reply with quote

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
View user's profile Send private message
TCL_no_TK
Owner


Joined: 25 Aug 2006
Posts: 509
Location: England, Yorkshire

PostPosted: Wed Mar 31, 2010 10:44 am    Post subject: Reply with quote

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
%
Rolling Eyes
_________________
TCL the misunderstood
Back to top
View user's profile Send private message Send e-mail
speechles
Revered One


Joined: 26 Aug 2006
Posts: 1398
Location: emerald triangle, california (coastal redwoods)

PostPosted: Wed Mar 31, 2010 4:47 pm    Post subject: Reply with quote

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.. Laughing

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
View user's profile Send private message
Luminous
Op


Joined: 12 Feb 2010
Posts: 146

PostPosted: Mon Apr 05, 2010 7:57 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber