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 unixtime into human readable time[SOLVED]
Goto page 1, 2, 3  Next
 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
ztian299
Halfop


Joined: 19 Apr 2008
Posts: 59
Location: *.no

PostPosted: Sun Jun 01, 2008 11:02 am    Post subject: convert unixtime into human readable time[SOLVED] Reply with quote

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
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Sun Jun 01, 2008 11:14 am    Post subject: Reply with quote

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
View user's profile Send private message
ztian299
Halfop


Joined: 19 Apr 2008
Posts: 59
Location: *.no

PostPosted: Sun Jun 01, 2008 11:41 am    Post subject: Reply with quote

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
View user's profile Send private message
strikelight
Owner


Joined: 07 Oct 2002
Posts: 708

PostPosted: Sun Jun 01, 2008 1:09 pm    Post subject: Reply with quote

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 Wink


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
View user's profile Send private message Visit poster's website
ztian299
Halfop


Joined: 19 Apr 2008
Posts: 59
Location: *.no

PostPosted: Sun Jun 01, 2008 3:17 pm    Post subject: Reply with quote

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
View user's profile Send private message
speechles
Revered One


Joined: 26 Aug 2006
Posts: 1398
Location: emerald triangle, california (coastal redwoods)

PostPosted: Sun Jun 01, 2008 3:23 pm    Post subject: Reply with quote

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
View user's profile Send private message
ztian299
Halfop


Joined: 19 Apr 2008
Posts: 59
Location: *.no

PostPosted: Sun Jun 01, 2008 3:37 pm    Post subject: Reply with quote

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
View user's profile Send private message
speechles
Revered One


Joined: 26 Aug 2006
Posts: 1398
Location: emerald triangle, california (coastal redwoods)

PostPosted: Sun Jun 01, 2008 3:51 pm    Post subject: Reply with quote

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
View user's profile Send private message
ztian299
Halfop


Joined: 19 Apr 2008
Posts: 59
Location: *.no

PostPosted: Sun Jun 01, 2008 3:55 pm    Post subject: Reply with quote

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
View user's profile Send private message
speechles
Revered One


Joined: 26 Aug 2006
Posts: 1398
Location: emerald triangle, california (coastal redwoods)

PostPosted: Sun Jun 01, 2008 4:00 pm    Post subject: Reply with quote

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
View user's profile Send private message
ztian299
Halfop


Joined: 19 Apr 2008
Posts: 59
Location: *.no

PostPosted: Sun Jun 01, 2008 4:05 pm    Post subject: Reply with quote

Still same :/
Back to top
View user's profile Send private message
speechles
Revered One


Joined: 26 Aug 2006
Posts: 1398
Location: emerald triangle, california (coastal redwoods)

PostPosted: Sun Jun 01, 2008 4:06 pm    Post subject: Reply with quote

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
_________________
speechles' eggdrop tcl archive


Last edited by speechles on Sun Jun 01, 2008 4:08 pm; edited 1 time in total
Back to top
View user's profile Send private message
ztian299
Halfop


Joined: 19 Apr 2008
Posts: 59
Location: *.no

PostPosted: Sun Jun 01, 2008 4:07 pm    Post subject: Reply with quote

php? lol. I'm not even using PHP. MySQLTCL works fine! so, whats the problem?
Back to top
View user's profile Send private message
speechles
Revered One


Joined: 26 Aug 2006
Posts: 1398
Location: emerald triangle, california (coastal redwoods)

PostPosted: Sun Jun 01, 2008 4:10 pm    Post subject: Reply with quote

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
View user's profile Send private message
ztian299
Halfop


Joined: 19 Apr 2008
Posts: 59
Location: *.no

PostPosted: Sun Jun 01, 2008 4:20 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Goto page 1, 2, 3  Next
Page 1 of 3

 
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