| View previous topic :: View next topic |
| Author |
Message |
ztian299 Halfop
Joined: 19 Apr 2008 Posts: 59 Location: *.no
|
Posted: Sun Jun 01, 2008 11:02 am Post subject: convert unixtime into human readable time[SOLVED] |
|
|
Hello,
I have this set now:
| Code: |
set time [unixtime]
|
I got logs stored with userinfo and unixtime for that info. So i need to calculate it.
Example:
| Quote: |
<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 |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Sun Jun 01, 2008 11:14 am Post subject: |
|
|
You might wish to try out the duration command available in eggies.
| Quote: | 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, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
ztian299 Halfop
Joined: 19 Apr 2008 Posts: 59 Location: *.no
|
Posted: Sun Jun 01, 2008 11:41 am Post subject: |
|
|
This solved it:
| Code: |
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 ;) |
|
| Back to top |
|
 |
strikelight Owner

Joined: 07 Oct 2002 Posts: 708
|
Posted: Sun Jun 01, 2008 1:09 pm Post subject: |
|
|
| ztian299 wrote: | This solved it:
| Code: |
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). |
|
| Back to top |
|
 |
ztian299 Halfop
Joined: 19 Apr 2008 Posts: 59 Location: *.no
|
Posted: Sun Jun 01, 2008 3:17 pm Post subject: |
|
|
hmm,
| Quote: |
;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? |
|
| Back to top |
|
 |
speechles Revered One

Joined: 26 Aug 2006 Posts: 1398 Location: emerald triangle, california (coastal redwoods)
|
Posted: Sun Jun 01, 2008 3:23 pm Post subject: |
|
|
| Quote: | | I got logs stored with userinfo and unixtime for that info. So i need to calculate it. |
| Code: | # 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: | | ;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. _________________ speechles' eggdrop tcl archive |
|
| Back to top |
|
 |
ztian299 Halfop
Joined: 19 Apr 2008 Posts: 59 Location: *.no
|
Posted: Sun Jun 01, 2008 3:37 pm Post subject: |
|
|
Ok, i got it stored in sql. My code is like this:
| Code: |
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:
| Quote: |
<me>.info blah
<bot> blah - Firstname: text Lastname: text Info: text - Added 4weeks 20hours and 13minutes ago
|
|
|
| Back to top |
|
 |
speechles Revered One

Joined: 26 Aug 2006 Posts: 1398 Location: emerald triangle, california (coastal redwoods)
|
Posted: Sun Jun 01, 2008 3:51 pm Post subject: |
|
|
| Code: | 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"
} |
_________________ speechles' eggdrop tcl archive |
|
| Back to top |
|
 |
ztian299 Halfop
Joined: 19 Apr 2008 Posts: 59 Location: *.no
|
Posted: Sun Jun 01, 2008 3:55 pm Post subject: |
|
|
| Quote: |
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? |
|
| Back to top |
|
 |
speechles Revered One

Joined: 26 Aug 2006 Posts: 1398 Location: emerald triangle, california (coastal redwoods)
|
Posted: Sun Jun 01, 2008 4:00 pm Post subject: |
|
|
| ztian299 wrote: | | Quote: |
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. | Quote: | | 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. _________________ speechles' eggdrop tcl archive
Last edited by speechles on Sun Jun 01, 2008 4:06 pm; edited 2 times in total |
|
| Back to top |
|
 |
ztian299 Halfop
Joined: 19 Apr 2008 Posts: 59 Location: *.no
|
Posted: Sun Jun 01, 2008 4:05 pm Post subject: |
|
|
| Still same :/ |
|
| Back to top |
|
 |
speechles Revered One

Joined: 26 Aug 2006 Posts: 1398 Location: emerald triangle, california (coastal redwoods)
|
Posted: Sun Jun 01, 2008 4:06 pm Post subject: |
|
|
| 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..  _________________ speechles' eggdrop tcl archive
Last edited by speechles on Sun Jun 01, 2008 4:08 pm; edited 1 time in total |
|
| Back to top |
|
 |
ztian299 Halfop
Joined: 19 Apr 2008 Posts: 59 Location: *.no
|
Posted: Sun Jun 01, 2008 4:07 pm Post subject: |
|
|
| php? lol. I'm not even using PHP. MySQLTCL works fine! so, whats the problem? |
|
| Back to top |
|
 |
speechles Revered One

Joined: 26 Aug 2006 Posts: 1398 Location: emerald triangle, california (coastal redwoods)
|
Posted: Sun Jun 01, 2008 4:10 pm Post subject: |
|
|
| 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.
| Quote: | | 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. _________________ speechles' eggdrop tcl archive
Last edited by speechles on Sun Jun 01, 2008 4:25 pm; edited 1 time in total |
|
| Back to top |
|
 |
ztian299 Halfop
Joined: 19 Apr 2008 Posts: 59 Location: *.no
|
Posted: Sun Jun 01, 2008 4:20 pm Post subject: |
|
|
| 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 |
|
| Back to top |
|
 |
|