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.
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:I have converted it into human readable format And it's right.
....

Let me guess. The format time uses isn't clock seconds (just numbers), but some combination of who knows what that you've never made us aware until this point... *slams face into keyboard*
Last edited by speechles on Sun Jun 01, 2008 4:27 pm, edited 1 time in total.
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
the unixtime indicates the time for the specific user. But what is wrong with that expression?
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
the unixtime indicates the time for the specific user. But what is wrong with that expression?
also, that unixtime isnt for the user.. haw.. time is NEVER retrieved because you failed to disclose it's contents (numbers/letters/etc).

It's expecting a numeric sequence of elapsed seconds (time) to be subtracted from (unitime/clock seconds). Isn't it painfully obvious what's wrong? *face slams into keyboard again* If your feeding it some human readable format for time.. then yeah, enjoy much syntax errors. Because it will null the value (time) if it isnt fully numeric (since used in a numeric fashion). Hence your error. Until you disclose how your (time) is formatted for human readability, we are quagmired.
.tcl set example1 1440
.tcl set example2 ""
.tcl set result [expr $example1-$example2]
> Tcl error: syntax error in expression "1440 - ": premature end of expression
This is your scenario.

Edit: read above notice the missing example2, this is your time.
Last edited by speechles on Sun Jun 01, 2008 4:42 pm, edited 2 times in total.
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
the unixtime indicates the time for the specific user. But what is wrong with that expression?

the unixtime is added to MySQL by

Code: Select all

set time [unixtime]
So not MY fault TCL makes it NOT readable?
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
the unixtime indicates the time for the specific user. But what is wrong with that expression?

the unixtime is added to MySQL by

Code: Select all

set time [unixtime]
So not MY fault TCL makes it NOT readable?
Until you post your entire script, or segments of it explaining more. All your doing is confusing me. So adieu, chow, adios.. hope to see [code]stuff in here[/code] posted by you soon.
z
ztian299
Halfop
Posts: 59
Joined: Sat Apr 19, 2008 4:57 pm
Location: *.no

Post by ztian299 »

I'm trying to make TCL calculate the time between the specific unixtime and the time that is right NOW. and then make a output like:
'4weeks 3days 2hours 1minute'
but as i see. It should not be easy!
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:I'm trying to make TCL calculate the time between the specific unixtime and the time that is right NOW. and then make a output like:
'4weeks 3days 2hours 1minute'
but as i see. It should not be easy!

Code: Select all

set time [unixtime]
putserv "PRIVMSG $chan :[duration [expr [clock seconds] - $time]]"
can you tell me what the output of this would be? Let's say the actual time it is now, is 13200 in seconds (it isn't we just say this). Now the first line is 'set time 13200'. Now in the message we take the difference betweeen clock seconds and 13200. Clock seconds will return the exact number of elapsed seconds at that moment, perhaps since its running after we set time, this is 13201. Now you have it take 13201-13200, and you get 1 second.

You fail to understand this. Unless you have a starting point in time, to subtract from your current time. You cannot do what you want.

[unixtime] == [clock seconds] == time it is right now

If you simply want to adjust for timezones, use clock format and within it an expr to subtract/add hours accordingly.
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

@ztian299:
Your foreach-loop expects you to use -flatlist with mysqlsel rather than -list. Change that, and everything should work with some code posted way up.

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" -flatlist]
foreach {nick fname lname info time} $search {
      putserv "PRIVMSG $chan :$nick - Firstname: $fname Lastname: $lname Info: $info - Added [duration [expr [clock seconds] - $time]] ago"
}
...
Another option would be to modify your foreach-loop:

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 {row} $search {
      putserv "PRIVMSG $chan :[lindex $row 0] - Firstname: [lindex $row 1] Lastname: [lindex $row 2] Info: [lindex $row 3] - Added [duration [expr [clock seconds] - [lindex $row 4]]] ago"
}...
@speechles:
Not to be rude, but what have you been smoking tonight? ;)


Edit: Fixed list index typo
NML_375
z
ztian299
Halfop
Posts: 59
Joined: Sat Apr 19, 2008 4:57 pm
Location: *.no

Post by ztian299 »

nml375: I didn't do anything else than change -list to -flatlist and everything works? :D pretty impressive. Thanks, how can i know next time if i should use -flatlist or just -list?
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

nml375 wrote:speechles:
Not to be rude, but what have you been smoking tonight? ;)
http://ereader.kiczek.com/little_girls.jpg

Only they aren't so little anymore, and have gone on to have children of their own. I expect being dutch you have some women of this kind you keep pampered. ;)
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Well, as I illustrated in my post, either way works, just as long as you write the rest of your code properly...

The following is copied from the tclmysql manual, which should illustrate the difference between the two different options:

Code: Select all

% ::mysql::sel $db "SELECT ID, NAME FROM FRIENDS" -list
{1 Joe} {2 Phil} {3 John}
% ::mysql::sel $db "SELECT ID, NAME FROM FRIENDS" -flatlist
{1 Joe 2 Phil 3 John}
With -list, you get a tcl-list, where each list-item is itself a tcl-list representing one row - having one list item for each column.
Or, in other words, to select the data in row x column y, you would use "puts stdout [lindex [lindex $result x] y]"

With -flatlist however, you get a tcl-list where each list-items represents one datacell. As the name suggests, the list have been "flattened", where each datacell follows the previous one (making it ideal for "foreach {nick fname lname info time} {" kind of structures, which will extract 5 elements from the list on each run).
NML_375
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

speechles wrote:...
I expect being dutch you have some women of this kind you keep pampered. ;)
Lol, sorry to disappoint you, but I'm "the Swedish Guy" ;)
NML_375
z
ztian299
Halfop
Posts: 59
Joined: Sat Apr 19, 2008 4:57 pm
Location: *.no

Post by ztian299 »

Could i do something like this:
if ("$chan" == "#somechannel"){set limit "5"}
and then use $limit in the select query?
to be honest i have tried, but got "extra characters after close-quote" and "after close-brace" why's that?
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

if {[string match $chan "#somechannel"]} { set limit 5 }
You used parenthesis in place of curly braces, this should work better. You only really need to use "quotes" when encapsulating spaces or oddball characters into a single field.
Last edited by speechles on Sun Jun 01, 2008 6:04 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

Code: Select all

if {[string match $chan "#blah"]}{set limit 5}

set search [mysqlsel $dbconnect "SELECT nick,fname,lname,info,time FROM table WHERE nick LIKE '$nick%' LIMIT $limit" -flatlist]
Giving me this error AGAIN. Wondering why it should be that hard to make a little limit!
Tcl error [pub:infouser] extra characters after close-brace
Post Reply