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.

convert time output

Help for those learning Tcl or writing their own scripts.
Post Reply
p
pipo
Voice
Posts: 16
Joined: Sat Nov 18, 2006 2:51 pm

convert time output

Post by pipo »

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: Select all

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: Select all

set addtime [unx2nps $timestamp]

Code: Select all

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"]
}
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

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 :D
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...
p
pipo
Voice
Posts: 16
Joined: Sat Nov 18, 2006 2:51 pm

Post by pipo »

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

Code: Select all

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:
[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
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

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'
p
pipo
Voice
Posts: 16
Joined: Sat Nov 18, 2006 2:51 pm

Post by pipo »

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

But I still dont get it :(

Tried few options, mm/dd/yy, day, dd monthname yy but still same error.
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

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"
p
pipo
Voice
Posts: 16
Joined: Sat Nov 18, 2006 2:51 pm

Post by pipo »

[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.
User avatar
Alchera
Revered One
Posts: 3344
Joined: Mon Aug 11, 2003 12:42 pm
Location: Ballarat Victoria, Australia
Contact:

Post by Alchera »

Sir_Fz wrote:Code:

Code: Select all

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
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

pipo wrote:
[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.
p
pipo
Voice
Posts: 16
Joined: Sat Nov 18, 2006 2:51 pm

Post by pipo »

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
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

Of course it's possible..I suggest you read the documentation.
p
pipo
Voice
Posts: 16
Joined: Sat Nov 18, 2006 2:51 pm

Post by pipo »

Solved it :D

a friend told me what to do:
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
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Code: Select all

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

set duration [duration [expr {$duetime - [unixtime]}]]
example:
.tcl set duetime [clock scan "11/25/06 00:10:00"]
Tcl: 1164413400
.tcl duration [expr {$duetime - [unixtime]}]
Tcl: 4 minutes 7 seconds
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

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...
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

I was just making it clear for him how to use it since he misused it and got a Tcl error.
Post Reply