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 

convert time output

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


Joined: 18 Nov 2006
Posts: 16

PostPosted: Wed Nov 22, 2006 5:21 pm    Post subject: convert time output Reply with quote

Thanks for the help in my previous topic

When my script announce a requested nick it shows the time when the nick was added to the db.txt file. In the db.txt file it is saved with the unixtime.

like:

!search nick

announce: <lastname> <frontname> was added on <addtime>

Is it posible to add someting to the script, so it shows how long ago the nick was added to the db.txt file?

someting like:

!search nick

announce: <lastname> <frontname> was added on <addtime> that was <## hours, ## minutes and ##> sec ago.


I dont know much about .tcl scripting, but I found the following lines in the script, that may help(?) :

Addnick:
Code:

set timestamp [check:stamp [lindex $arg 2]]
  set rlstmp [lindex $arg 0]
  if { $rlstmp == "" } { putserv "NOTICE $nick : USAGE\: !addnick LASTNAME FRONTNAME UNXTiME "; return 0 }




annouce:
Code:

set addtime [unx2nps $timestamp]



Code:

proc check:stamp { timestamp } {
 regsub -- {[nN][oO][wW]} $timestamp "" timestamp
 if { $timestamp == "" || $timestamp == "\-" } { return [unixtime] } else { return $timestamp}
}


proc unx2nps { timestamp } {
 if {[regexp "\[^\\d\]" $timestamp]} { error "unx2nps: parameter is not a valid unix timestamp" }
 if {$timestamp > "2000000000"} { error "unx2nps: parameter is too large" }
 return [clock format $timestamp -format "%Y/%m/%d %H:%M:%S"]
}
Back to top
View user's profile Send private message
De Kus
Revered One


Joined: 15 Dec 2002
Posts: 1361
Location: Germany

PostPosted: Thu Nov 23, 2006 2:48 pm    Post subject: Reply with quote

read that topic: http://forum.egghelp.org/viewtopic.php?t=12721
just switch places of the variable and [unixtime], since we want to know long it is ago instead of how long it will be Very Happy
_________________
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
Back to top
View user's profile Send private message MSN Messenger
pipo
Voice


Joined: 18 Nov 2006
Posts: 16

PostPosted: Thu Nov 23, 2006 4:16 pm    Post subject: Reply with quote

I have change it into this this (think that id what you told) :

Code:

set duetime [clock scan "mm/dd/yy hh:mm:ss"]

set duration [duration [expr {[unixtime] - $duetime}]]


Now when I start my bot, I get this error:

Quote:

[21:07] unable to convert date-time string "mm/dd/yy hh:mm:ss"
while executing
"clock scan "mm/dd/yy hh:mm:ss""
invoked from within
"set duetime [clock scan "mm/dd/yy hh:mm:ss"]"


Any idea what is wrong?

Thanks
Back to top
View user's profile Send private message
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Thu Nov 23, 2006 4:53 pm    Post subject: Reply with quote

Read the clock manpage, the scan command requires specific formats for the date, typically "mon day, year" (note the comma) I made a post around here somewhere that describes the exact formats, try doing a search for 'clock scan'
Back to top
View user's profile Send private message
pipo
Voice


Joined: 18 Nov 2006
Posts: 16

PostPosted: Thu Nov 23, 2006 7:59 pm    Post subject: Reply with quote

I found http://forum.egghelp.org/viewtopic.php?t=12507

But I still dont get it Sad

Tried few options, mm/dd/yy, day, dd monthname yy but still same error.
Back to top
View user's profile Send private message
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Thu Nov 23, 2006 8:09 pm    Post subject: Reply with quote

set duetime [clock scan "mm/dd/yy hh:mm:ss"]

[21:07] unable to convert date-time string "mm/dd/yy hh:mm:ss"

You are passing it the literal string "mm/dd/yy hh:mm:ss" and NOT variables! "$mm/$dd/$yy $hh:$mm:$ss"
Back to top
View user's profile Send private message
pipo
Voice


Joined: 18 Nov 2006
Posts: 16

PostPosted: Thu Nov 23, 2006 8:36 pm    Post subject: Reply with quote

Quote:

[01:29] Tcl error in file 'eggdrop.conf':
[01:29] can't read "mm": no such variable
while executing
"clock scan "$mm/$dd/$yy $hh:$mm:$ss""
invoked from within
"set duetime [clock scan "$mm/$dd/$yy $hh:$mm:$ss"]"


Thanks for your patience so far.
Back to top
View user's profile Send private message
Alchera
Revered One


Joined: 11 Aug 2003
Posts: 3344
Location: Ballarat Victoria, Australia

PostPosted: Thu Nov 23, 2006 8:51 pm    Post subject: Reply with quote

Sir_Fz wrote:
Code:
Code:
set duetime [clock scan "mm/dd/yy hh:mm:ss"]

set duration [duration [expr {$duetime - [unixtime]}]]


Read about clock scan.

_________________
Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM
Back to top
View user's profile Send private message Visit poster's website
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Thu Nov 23, 2006 9:03 pm    Post subject: Reply with quote

[quote="pipo"]
Quote:

[01:29] Tcl error in file 'eggdrop.conf':
[01:29] can't read "mm": no such variable
while executing
"clock scan "$mm/$dd/$yy $hh:$mm:$ss""
invoked from within
"set duetime [clock scan "$mm/$dd/$yy $hh:$mm:$ss"]"


What and where does your script set as variables for month, day, year, hour minutes and seconds? That is what you need to use.
Back to top
View user's profile Send private message
pipo
Voice


Joined: 18 Nov 2006
Posts: 16

PostPosted: Fri Nov 24, 2006 6:40 am    Post subject: Reply with quote

Quote:

What and where does your script set as variables for month, day, year, hour minutes and seconds? That is what you need to use.


Looks like the script doesnt got such variable. Is it possible to add them to the script? And what is the code?

Thanks again
Back to top
View user's profile Send private message
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Fri Nov 24, 2006 6:56 am    Post subject: Reply with quote

Of course it's possible..I suggest you read the documentation.
Back to top
View user's profile Send private message
pipo
Voice


Joined: 18 Nov 2006
Posts: 16

PostPosted: Fri Nov 24, 2006 10:41 am    Post subject: Reply with quote

Solved it Very Happy

a friend told me what to do:

Quote:

Well it's simple if you have the time already in unixtime format... that's the code to calculate the duration:


set addtime [unx2nps $timestamp]

becomes

set addtime [duration [expr {[unixtime] - $timestamp}]]

Well if "addtime" isn't used in other lines... otherwise just let this line as it is and instead of putting the result of "duration" in "addtime" variable define another variable.. like "addedsince"...and in the "PUTSERV" that sends the annouce to the user change "addtime" by "addedsince".


But thanks for all the help, your time and ofcourse your patience, lol
Back to top
View user's profile Send private message
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Fri Nov 24, 2006 12:07 pm    Post subject: Reply with quote

Quote:
Code:
set duetime [clock scan "mm/dd/yy hh:mm:ss"]

set duration [duration [expr {$duetime - [unixtime]}]]

example:
Quote:
.tcl set duetime [clock scan "11/25/06 00:10:00"]
Tcl: 1164413400
.tcl duration [expr {$duetime - [unixtime]}]
Tcl: 4 minutes 7 seconds

_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
De Kus
Revered One


Joined: 15 Dec 2002
Posts: 1361
Location: Germany

PostPosted: Sun Nov 26, 2006 11:07 am    Post subject: Reply with quote

I was only refering to the second line. does he actually need time scanning from string? I thought he already has a unix time stamp in a variable...
_________________
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
Back to top
View user's profile Send private message MSN Messenger
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Sun Nov 26, 2006 11:49 am    Post subject: Reply with quote

I was just making it clear for him how to use it since he misused it and got a Tcl error.
_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
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