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 

Time problem...

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


Joined: 04 Jun 2006
Posts: 22

PostPosted: Sun Dec 10, 2006 7:18 pm    Post subject: Time problem... Reply with quote

my code
Code:
   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:
<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:
<eggdrop> mytime 10.12.2006 21:58:55 timeago: 5w 1d 5h 27m(in) 39s(ec)


THX
Back to top
View user's profile Send private message
rosc2112
Revered One


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

PostPosted: Sun Dec 10, 2006 8:00 pm    Post subject: Reply with quote

Code:

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.
Back to top
View user's profile Send private message
user
 


Joined: 18 Mar 2003
Posts: 1452
Location: Norway

PostPosted: Mon Dec 11, 2006 8:15 am    Post subject: Reply with quote

rosc2112 wrote:
Code:
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:
regsub -all { ([wdhms])[^ ]+} $timeago \\1 timeago

or
Code:
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"?
Back to top
View user's profile Send private message
Access
Voice


Joined: 04 Jun 2006
Posts: 22

PostPosted: Mon Dec 11, 2006 10:26 am    Post subject: Reply with quote

rosc2112 wrote:

Code:
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?
Back to top
View user's profile Send private message
user
 


Joined: 18 Mar 2003
Posts: 1452
Location: Norway

PostPosted: Mon Dec 11, 2006 11:38 am    Post subject: Reply with quote

Code:
clock format $unxtime -format "%d.%m.%Y %T"

_________________
Have you ever read "The Manual"?
Back to top
View user's profile Send private message
Access
Voice


Joined: 04 Jun 2006
Posts: 22

PostPosted: Mon Dec 11, 2006 12:47 pm    Post subject: Reply with quote

???

do u know what i want?

i want to convert

Code:
2006-10-28 00:08:42

or
Code:
1161986922


to

Code:
28.10.2006 00:08:42
Back to top
View user's profile Send private message
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Mon Dec 11, 2006 1:20 pm    Post subject: Reply with quote

Yeah, and that's what you got. $unxtime in this case would be '1161986922'.
_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
rosc2112
Revered One


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

PostPosted: Mon Dec 11, 2006 1:50 pm    Post subject: Reply with quote

I dunno why I didn't think of using [string map] that would be simpler =)
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