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 

Abbreviate Time

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


Joined: 26 Feb 2008
Posts: 57

PostPosted: Sat Jan 10, 2009 6:58 pm    Post subject: Abbreviate Time Reply with quote

Is there a way when my bot announces the time instead of hours it will display hrs (same for minutes and seconds)?
set time1 [unixtime]
incr time1 -$timestamp
set ago [duration $time1]
Back to top
View user's profile Send private message
speechles
Revered One


Joined: 26 Aug 2006
Posts: 1398
Location: emerald triangle, california (coastal redwoods)

PostPosted: Sat Jan 10, 2009 7:05 pm    Post subject: Reply with quote

Code:
set ago [string map {"year" "yr" "week" "wk" "day" "dy" "hour" "hr" "minute" "min" "second" "sec"} [duration $time1]]

_________________
speechles' eggdrop tcl archive
Back to top
View user's profile Send private message
intel
Halfop


Joined: 26 Feb 2008
Posts: 57

PostPosted: Sat Jan 10, 2009 7:24 pm    Post subject: Reply with quote

Thanx, but will that do hrs or just hr. Like 5 hrs ago or 5 hr ago?
Back to top
View user's profile Send private message
speechles
Revered One


Joined: 26 Aug 2006
Posts: 1398
Location: emerald triangle, california (coastal redwoods)

PostPosted: Sat Jan 10, 2009 7:40 pm    Post subject: Reply with quote

intel wrote:
Thanx, but will that do hrs or just hr. Like 5 hrs ago or 5 hr ago?

It will change any occurence of "hour" to "hr" which is part of both words, hour and hours. So "hours" will be changed to "hrs", yes. The same goes for the rest of the abbreviations.
_________________
speechles' eggdrop tcl archive
Back to top
View user's profile Send private message
intel
Halfop


Joined: 26 Feb 2008
Posts: 57

PostPosted: Sat Jan 10, 2009 8:03 pm    Post subject: Reply with quote

awesome... thanx Laughing
Back to top
View user's profile Send private message
intel
Halfop


Joined: 26 Feb 2008
Posts: 57

PostPosted: Mon Jan 12, 2009 8:02 am    Post subject: Reply with quote

oh would you know how to get rid of the space? It says 1 hr 15 min ago would like 1hr 15min ago


Thanks.
Back to top
View user's profile Send private message
arfer
Master


Joined: 26 Nov 2004
Posts: 436
Location: Manchester, UK

PostPosted: Mon Jan 12, 2009 8:14 am    Post subject: Reply with quote

You must include the space character in the mapped items to be replaced as follows :-

Code:

set ago [string map {" year" "yr" " week" "wk" " day" "dy" " hour" "hr" " minute" "min" " second" "sec"} [duration $time1]]


For example :-

[12:19] <@arfer> % return [string map {" year" "yr" " week" "wk" " day" "dy" " hour" "hr" " minute" "min" " second" "sec"} [duration [unixtime]]]
[12:19] <@Baal> 39yrs 3wks 12hrs 19mins 6secs
Back to top
View user's profile Send private message
intel
Halfop


Joined: 26 Feb 2008
Posts: 57

PostPosted: Mon Jan 12, 2009 9:36 am    Post subject: Reply with quote

Great. It works. Thanx appreciate the all the help.
Just curious if I wanted say 12h 15m 10s would that just be
" hour" "" " minutes" "" or will just put either nothing or a s at the end (like 12 or 12s instead of 12hr or 12hrs)?
Back to top
View user's profile Send private message
incith
Master


Joined: 23 Apr 2005
Posts: 275
Location: Canada

PostPosted: Mon Jan 12, 2009 5:07 pm    Post subject: Reply with quote

How about you just fiddle with it until it works the way you want..

http://www.tcl.tk/man/tcl8.2.3/TclCmd/string.htm#M34
_________________
; Answer a few unanswered posts!
Back to top
View user's profile Send private message
intel
Halfop


Joined: 26 Feb 2008
Posts: 57

PostPosted: Mon Jan 12, 2009 6:01 pm    Post subject: Reply with quote

lol been tryin... used /m /s [m] [s] not working... so obviously doing something wrong.
Back to top
View user's profile Send private message
incith
Master


Joined: 23 Apr 2005
Posts: 275
Location: Canada

PostPosted: Mon Jan 12, 2009 8:00 pm    Post subject: Reply with quote

You are mapping "{from} {to}", so if you want to replace hour with h, ...

{hour} {h} {minute} {m} etc.. you might need to do extra ones for the s, or try with {hour*} but that might end up replacing the whole string <_<. maybe hour? to check for the 1 additional char.
_________________
; Answer a few unanswered posts!
Back to top
View user's profile Send private message
speechles
Revered One


Joined: 26 Aug 2006
Posts: 1398
Location: emerald triangle, california (coastal redwoods)

PostPosted: Mon Jan 12, 2009 8:08 pm    Post subject: Reply with quote

Code:
set ago [string map {" years" "y" " weeks" "w" " days" "d" " hours" "h" " minutes" "m" " seconds" "s" " year" "y" " week" "w" " day" "d" " hour" "h" " minute" "m" " second" "s"} [duration $time1]]

Make a big long string map in that case. Incith was correct, test these things on your own, so you learn intuitively and interactively.
_________________
speechles' eggdrop tcl archive
Back to top
View user's profile Send private message
intel
Halfop


Joined: 26 Feb 2008
Posts: 57

PostPosted: Mon Jan 12, 2009 9:31 pm    Post subject: Reply with quote

Thanx. I did try that really long way but I didnt have it in that order so it did not work. It was still doing ms (for minutes) and ss (for seconds)

Thanx. Appreciate the help.
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