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 

[Help] Calculate time [Solved]

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
w00f
Halfop


Joined: 04 Oct 2006
Posts: 49

PostPosted: Wed Oct 04, 2006 7:07 pm    Post subject: [Help] Calculate time [Solved] Reply with quote

hi there.

i need to know if there are any kind of way to calculate the time since i've added something that i'm searching for and the time when i trigger a certain command.

[23:54:41] (@w00f) !adefine w00f test!
[23:54:43] (@w00f) !define w00f
[23:54:44] (@b0T) w00f: test! :: added at 10/04/06 23:54:41

what i want is to convert that time (10/04/06 23:54:41 , i save the time when i add the definition) to something like this:

[23:54:44] (@b0T) w00f: test! :: added 3s ago.

a month later

[23:54:44] (@b0T) w00f: test! :: added 1m 3s ago.
or
[23:54:44] (@b0T) w00f: test! :: added 4w 3s ago.
or 4w 0d 0h 0m 3s ago

something like that would be great.


tnks in advance.


Last edited by w00f on Sat Oct 21, 2006 5:08 pm; edited 1 time in total
Back to top
View user's profile Send private message
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Wed Oct 04, 2006 11:14 pm    Post subject: Reply with quote

Convert the time to EPOCH time, with clock scan:

set mytime [clock scan "10/04/06 23:54:41"]
set nowtime [clock scan [strftime "%m/%d/%y %T"]]

then use the 'duration' command to diff the times:

set difftime [duration [expr $nowtime - $mytime]]

Hmm now that I look at my date.tcl script, you can simplify the difftime by just using [unixtime] to get the current time:

set difftime [duration [expr [unixtime] - $mytime]]

The date.tcl script I (re)did has a whole lot of examples of manipulating dates/times and checking for leap years and valid input, reading/writing to files, and so forth and so on. It's in the tcl archive if you want to look at it.
Back to top
View user's profile Send private message
w00f
Halfop


Joined: 04 Oct 2006
Posts: 49

PostPosted: Thu Oct 05, 2006 1:42 pm    Post subject: Reply with quote

Thanks man , works great.

i'll take a look at date.tcl , could be usefull ;D
Back to top
View user's profile Send private message
metroid
Owner


Joined: 16 Jun 2004
Posts: 771

PostPosted: Fri Oct 06, 2006 1:45 am    Post subject: Reply with quote

Sorry but why would you use clock scan on the current time if [clock seconds] or [unixtime] is available?

That just seems like you're making TCL do something that it doesn't have to.
Back to top
View user's profile Send private message
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Fri Oct 06, 2006 2:51 am    Post subject: Reply with quote

rosc2112 wrote:

Hmm now that I look at my date.tcl script, you can simplify the difftime by just using [unixtime] to get the current time:

set difftime [duration [expr [unixtime] - $mytime]]
Back to top
View user's profile Send private message
w00f
Halfop


Joined: 04 Oct 2006
Posts: 49

PostPosted: Sun Oct 08, 2006 11:27 am    Post subject: Reply with quote

I've started to play with dates and stuff like that but in one the codes i've got a problem...i saw date.tcl but i was a little confused about how i can convert a date(10/01/06 09:20 for example[month/day/year Hours:minutes) to "clock second" format.

i've tried some codes but none of them seems to work as i want.
need help =X
Back to top
View user's profile Send private message
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Sun Oct 08, 2006 6:59 pm    Post subject: Reply with quote

clock seconds
Return the current date and time as a system-dependent integer value. The unit of the value is seconds, allowing it to be used for relative time calculations. The value is usually defined as total elapsed time from an ``epoch''. You shouldn't assume the value of the epoch.

So the [clock seconds] command will produce the current EPOCH time:
set now [clock seconds]

If you're wanting to convert a specific date and time into the EPOCH time, you use:
set mytime [clock scan "10/04/06 23:54:41"]

check the clock manpage for the formats for the date, the command is particular about the format (eg, month day,<comma required> year <time format>)

Date:
The acceptable formats are
mm/dd/yy (10/08/06)
monthname dd, yy (october 08, 06 or october 08, 2006)
dd monthname yy (08 october 06 or 08 october 2006)
day, dd monthname yy (sun, 08 october 06)
CCyymmdd (20061008 or 061008 )
CCyy-mm-dd (2006-10-08 or 06-10-08 )
dd-monthname-CCyy (08-october-2006 or 08-october-06)

The default year is the current year. If the year is less than 100, we
treat the years 00-68 as 2000-2068 and the years 69-99 as 1969-1999. Not all platforms can represent the years 38-70, so an error may result if these years are used.

Time:
A time of day, which is of the form:
hh:mm:ss
meridian zone
hhmm meridian zone
If no meridian is specified, hh is interpreted on a 24-hour clock.

Also note that the date/time have to be within double-quotes " "
Back to top
View user's profile Send private message
w00f
Halfop


Joined: 04 Oct 2006
Posts: 49

PostPosted: Mon Oct 09, 2006 5:32 pm    Post subject: Reply with quote

tnks man (one more time)
I have everything to work now.

u've been a great help ;D
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
Page 1 of 1

 
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