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 unixtime into human readable time[SOLVED]

Help for those learning Tcl or writing their own scripts.
z
ztian299
Halfop
Posts: 59
Joined: Sat Apr 19, 2008 4:57 pm
Location: *.no

convert unixtime into human readable time[SOLVED]

Post by ztian299 »

Hello,

I have this set now:

Code: Select all

set time [unixtime]
I got logs stored with userinfo and unixtime for that info. So i need to calculate it.

Example:
<me>.info test
<bot> nick: test have info set 1year 4weeks and 2days ago.
I got everything else coded, just need the calculate. tried to find some info on google, but not giving me enough info. Thanks in advance
Last edited by ztian299 on Tue Jun 03, 2008 3:51 pm, edited 4 times in total.
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

You might wish to try out the duration command available in eggies.
duration <seconds>
Returns: the number of seconds converted into years, weeks, days, hours, minutes, and seconds. 804600 seconds is turned into 1 week 2 days 7 hours 30 minutes.
Module: core
NML_375
z
ztian299
Halfop
Posts: 59
Joined: Sat Apr 19, 2008 4:57 pm
Location: *.no

Post by ztian299 »

This solved it:

Code: Select all

set time [unixtime]
set calc [clock format $time %m\%d/%H:%M:%S]
putserv "PRIVMSG $chan :[duration [expr [clock seconds] - $time]]"
}
Anyway, thanks for help. Hope someone else can use this too ;)
User avatar
strikelight
Owner
Posts: 708
Joined: Mon Oct 07, 2002 10:39 am
Contact:

Post by strikelight »

ztian299 wrote:This solved it:

Code: Select all

set time [unixtime]
set calc [clock format $time %m\%d/%H:%M:%S]
putserv "PRIVMSG $chan :[duration [expr [clock seconds] - $time]]"
}
Anyway, thanks for help. Hope someone else can use this too ;)
mmm... for starters, you don't do anything with $calc... Secondly, your [duration [expr [clock seconds] - $time]] will most likely result in a reply of 0 seconds or 1 second or something of that nature, since [clock seconds] and [unixtime] are essentially the same (thus, x - x = 0) (one being native to eggdrop, the other Tcl in general).
z
ztian299
Halfop
Posts: 59
Joined: Sat Apr 19, 2008 4:57 pm
Location: *.no

Post by ztian299 »

hmm,
;set timezor 1212336809
;set testing [clock format $timezor -format %m\%d/%H:%M:%S]
;set own [duration [expr [clock seconds] - $timezor]]
<SafeTCL> blabla: #2 (832 clicks) Tcl: 3 hours, 54 minutes, 8 seconds
what's a better way?
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

I got logs stored with userinfo and unixtime for that info. So i need to calculate it.

Code: Select all

# this is logged somewhere, read the time in
set time $filetime
putserv "PRIVMSG $chan :[duration [expr [clock seconds] - $time]]"
filetime of course, you need to read in (you said you stored these somewhere, read it in), and it must be LESS than the current clock seconds. If its equal, your duration will be ZERO. If it's greater, your duration will be some insane 1753weeks etc.

Note:

Code: Select all

;set testing [clock format $timezor -format %m\%d/%H:%M:%S] 
You aren't using testing for anything, why do you waste time evaluating any of this? You can remove it, it's clutter.
z
ztian299
Halfop
Posts: 59
Joined: Sat Apr 19, 2008 4:57 pm
Location: *.no

Post by ztian299 »

Ok, i got it stored in sql. My code is like this:

Code: Select all

set klokka [unixtime]
set nick [lindex [split $text] 0]
     set search [mysqlsel $dbconnect "SELECT nick,fname,lname,info,time FROM table WHERE nick LIKE '$nick%' LIMIT 2" -list]
      foreach {nick fname lname info time} $search {
      putserv "PRIVMSG $chan :$nick - Firstname: $fname Lastname: $fname Info: $info - Added [clock format $klokka -format %m\%d/%H:%M:%S][duration [expr [clock seconds] - $time]] ago"
}
This will not properly, why?I'm trying to get it working like this:
<me>.info blah
<bot> blah - Firstname: text Lastname: text Info: text - Added 4weeks 20hours and 13minutes ago
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

Code: Select all

set nick [lindex [split $text] 0]
set search [mysqlsel $dbconnect "SELECT nick,fname,lname,info,time FROM table WHERE nick LIKE '$nick%' LIMIT 2" -list]
foreach {nick fname lname info time} $search {
      putserv "PRIVMSG $chan :$nick - Firstname: $fname Lastname: $lname Info: $info - Added [duration [expr [clock seconds] - $time]] ago"
}
z
ztian299
Halfop
Posts: 59
Joined: Sat Apr 19, 2008 4:57 pm
Location: *.no

Post by ztian299 »

Tcl error [pub:nickinfo]: syntax error in expression "1212352944 - ": premature end of expression
Now i have same code as you speechles. and got this error?
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

ztian299 wrote:
Tcl error [pub:nickinfo]: syntax error in expression "1212352944 - ": premature end of expression
Now i have same code as you speechles. and got this error?
Lmao, that sounds almost sexual. Like the bot is having performance issues in it's bedroom.. $TIME isn't being filled and is left blank or null, your php is flawed. Once you solve that, we can proceed.
Added [duration [expr [clock seconds] - $time]] ago"
This expression is your problem. Until you can retrieve time properly from your database, this expression is doomed.
Last edited by speechles on Sun Jun 01, 2008 4:06 pm, edited 2 times in total.
z
ztian299
Halfop
Posts: 59
Joined: Sat Apr 19, 2008 4:57 pm
Location: *.no

Post by ztian299 »

Still same :/
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

ztian299 wrote:Still same :/
Of course it is, read my post above. You are not using php correctly, or are using the mysql tcl package incorrectly. Both of which have nothing to do with correctly using duration. Maybe you should start a new thread, and dedicate it to mysql tcl.. :wink:
Last edited by speechles on Sun Jun 01, 2008 4:08 pm, edited 1 time in total.
z
ztian299
Halfop
Posts: 59
Joined: Sat Apr 19, 2008 4:57 pm
Location: *.no

Post by ztian299 »

php? lol. I'm not even using PHP. MySQLTCL works fine! so, whats the problem?
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

ztian299 wrote:php? lol. I'm not even using PHP. MySQLTCL works fine! so, whats the problem?
http://www.w3schools.com/PHP/php_mysql_intro.asp
I'm done debating this guy. You ARE using php. What do you think the tcl layer speaks to? to a magic genie in the lamp? It talks to the php which runs the sql database. So the sql request is YES in php. Now the problem you have, is you are not listening, and perhaps arrogant. So slow down. Realize the expression before fails, because the php sending data back to the tcl script is NOT returning time correctly. Until it does, you CANNOT do what you want to do.
set search [mysqlsel $dbconnect "SELECT nick,fname,lname,info,time FROM table WHERE nick LIKE '$nick%' LIMIT 2" -list]
Notice the PHP in bold above, this is more than likely your problem. It's wrong, as it is NOT having a time field returned. It's left blank or nulled.

NOTE: the [solved] on your thread indicates finished. If you have more issues, please remove the [SOLVED] from the title.
Last edited by speechles on Sun Jun 01, 2008 4:25 pm, edited 1 time in total.
z
ztian299
Halfop
Posts: 59
Joined: Sat Apr 19, 2008 4:57 pm
Location: *.no

Post by ztian299 »

Hmm, sorry but im not using PHP, im using eggdrop+mysqltcl+MySQL! that's it! I have double checked the 'time' field in mysql. And it's working. I have converted it into human readable format And it's right. Don't know how you can say this is for PHP. But not my problem. Sorry if i said anything dumb, but im not running with or through PHP. but why isn't this working like it should? As you say. It could be any problem getting the value of time! But don't know why
Post Reply