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.

Time problem...

Help for those learning Tcl or writing their own scripts.
Post Reply
A
Access
Voice
Posts: 22
Joined: Sun Jun 04, 2006 6:31 am

Time problem...

Post by Access »

my code

Code: Select all

   set mytime 2006-12-10 21:58:55
   set unxtime [clock scan $mytime]
   set now [unixtime] 
   set timeago [duration [expr ($now - $unxtime)]]
   putchan  $chan "mytime: $mytime timeago: $timeago
my output

Code: Select all

<eggdrop> mytime 2006-12-10 21:58:55 timeago: 5 weeks 1 day 5 hours 27 minutes 39 seconds

how the code must be look to get following output?

Code: Select all

<eggdrop> mytime 10.12.2006 21:58:55 timeago: 5w 1d 5h 27m(in) 39s(ec)
THX
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

Code: Select all

set timeago [duration [expr ($now - $unxtime)]] 
set week "";set day "";set hour ""';set min "";set sec ""
regexp {([0-9]) week.*? ([0-9]) day.*? ([0-9]) hour.*? ([0-9]) minute.*? ([0-9]) second.*?} $timeago week day hour min sec
putchan $chan "mytime $mytime: timeago: $week\w $day\d $hour\h $min\m $sec\s"
#antiwordwrap#--------------------------------------------------------------------------------------------------------------
That's one way.
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

rosc2112 wrote:

Code: Select all

regexp {([0-9]) week.*? ([0-9]) day.*? ([0-9]) hour.*? ([0-9]) minute.*? ([0-9]) second.*?} $timeago week day hour min sec
That pattern requires all units to be present in the string (which will not always be the case..)
Try something like this instead:

Code: Select all

regsub -all { ([wdhms])[^ ]+} $timeago \\1 timeago
or

Code: Select all

set timeago [string map {" weeks" w " week" w " days" d " day" d " hours" h " hour" h " minutes" m " minute" m " seconds" s " second" s} $timeago]
Have you ever read "The Manual"?
A
Access
Voice
Posts: 22
Joined: Sun Jun 04, 2006 6:31 am

Post by Access »

rosc2112 wrote:

Code: Select all

set timeago [string map {" weeks" w " week" w " days" d " day" d " hours" h " hour" h " minutes" m " minute" m " seconds" s " second" s} $timeago]
Works great, thx!


And whats about the $mytime variable? anyone an idea to solve this?
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

Code: Select all

clock format $unxtime -format "%d.%m.%Y %T"
Have you ever read "The Manual"?
A
Access
Voice
Posts: 22
Joined: Sun Jun 04, 2006 6:31 am

Post by Access »

???

do u know what i want?

i want to convert

Code: Select all

2006-10-28 00:08:42
or

Code: Select all

1161986922
to

Code: Select all

28.10.2006 00:08:42
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Yeah, and that's what you got. $unxtime in this case would be '1161986922'.
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

I dunno why I didn't think of using [string map] that would be simpler =)
Post Reply