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.
Help for those learning Tcl or writing their own scripts.
Access
Voice
Posts: 22 Joined: Sun Jun 04, 2006 6:31 am
Post
by Access » Sun Dec 10, 2006 7:18 pm
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
rosc2112
Revered One
Posts: 1454 Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania
Post
by rosc2112 » Sun Dec 10, 2006 8:00 pm
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
Posts: 1452 Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway
Post
by user » Mon Dec 11, 2006 8:15 am
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"?
Access
Voice
Posts: 22 Joined: Sun Jun 04, 2006 6:31 am
Post
by Access » Mon Dec 11, 2006 10:26 am
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
Posts: 1452 Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway
Post
by user » Mon Dec 11, 2006 11:38 am
Code: Select all
clock format $unxtime -format "%d.%m.%Y %T"
Have you ever read "The Manual"?
Access
Voice
Posts: 22 Joined: Sun Jun 04, 2006 6:31 am
Post
by Access » Mon Dec 11, 2006 12:47 pm
???
do u know what i want?
i want to convert
or
to
Sir_Fz
Revered One
Posts: 3794 Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:
Post
by Sir_Fz » Mon Dec 11, 2006 1:20 pm
Yeah, and that's what you got. $unxtime in this case would be '1161986922'.
rosc2112
Revered One
Posts: 1454 Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania
Post
by rosc2112 » Mon Dec 11, 2006 1:50 pm
I dunno why I didn't think of using [string map] that would be simpler =)