| View previous topic :: View next topic |
| Author |
Message |
pipo Voice
Joined: 18 Nov 2006 Posts: 16
|
Posted: Wed Nov 22, 2006 5:21 pm Post subject: convert time output |
|
|
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 |
|
 |
De Kus Revered One

Joined: 15 Dec 2002 Posts: 1361 Location: Germany
|
Posted: Thu Nov 23, 2006 2:48 pm Post subject: |
|
|
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  _________________ 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 |
|
 |
pipo Voice
Joined: 18 Nov 2006 Posts: 16
|
Posted: Thu Nov 23, 2006 4:16 pm Post subject: |
|
|
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 |
|
 |
rosc2112 Revered One

Joined: 19 Feb 2006 Posts: 1454 Location: Northeast Pennsylvania
|
Posted: Thu Nov 23, 2006 4:53 pm Post subject: |
|
|
| 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 |
|
 |
pipo Voice
Joined: 18 Nov 2006 Posts: 16
|
|
| Back to top |
|
 |
rosc2112 Revered One

Joined: 19 Feb 2006 Posts: 1454 Location: Northeast Pennsylvania
|
Posted: Thu Nov 23, 2006 8:09 pm Post subject: |
|
|
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 |
|
 |
pipo Voice
Joined: 18 Nov 2006 Posts: 16
|
Posted: Thu Nov 23, 2006 8:36 pm Post subject: |
|
|
| 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 |
|
 |
Alchera Revered One

Joined: 11 Aug 2003 Posts: 3344 Location: Ballarat Victoria, Australia
|
Posted: Thu Nov 23, 2006 8:51 pm Post subject: |
|
|
| 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 |
|
 |
rosc2112 Revered One

Joined: 19 Feb 2006 Posts: 1454 Location: Northeast Pennsylvania
|
Posted: Thu Nov 23, 2006 9:03 pm Post subject: |
|
|
[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 |
|
 |
pipo Voice
Joined: 18 Nov 2006 Posts: 16
|
Posted: Fri Nov 24, 2006 6:40 am Post subject: |
|
|
| 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 |
|
 |
rosc2112 Revered One

Joined: 19 Feb 2006 Posts: 1454 Location: Northeast Pennsylvania
|
Posted: Fri Nov 24, 2006 6:56 am Post subject: |
|
|
| Of course it's possible..I suggest you read the documentation. |
|
| Back to top |
|
 |
pipo Voice
Joined: 18 Nov 2006 Posts: 16
|
Posted: Fri Nov 24, 2006 10:41 am Post subject: |
|
|
Solved it
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 |
|
 |
Sir_Fz Revered One

Joined: 27 Apr 2003 Posts: 3793 Location: Lebanon
|
Posted: Fri Nov 24, 2006 12:07 pm Post subject: |
|
|
| 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 |
|
 |
De Kus Revered One

Joined: 15 Dec 2002 Posts: 1361 Location: Germany
|
Posted: Sun Nov 26, 2006 11:07 am Post subject: |
|
|
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 |
|
 |
Sir_Fz Revered One

Joined: 27 Apr 2003 Posts: 3793 Location: Lebanon
|
Posted: Sun Nov 26, 2006 11:49 am Post subject: |
|
|
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 |
|
 |
|