| View previous topic :: View next topic |
| Author |
Message |
intel Halfop
Joined: 26 Feb 2008 Posts: 57
|
Posted: Sat Jan 10, 2009 6:58 pm Post subject: Abbreviate Time |
|
|
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 |
|
 |
speechles Revered One

Joined: 26 Aug 2006 Posts: 1398 Location: emerald triangle, california (coastal redwoods)
|
Posted: Sat Jan 10, 2009 7:05 pm Post subject: |
|
|
| 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 |
|
 |
intel Halfop
Joined: 26 Feb 2008 Posts: 57
|
Posted: Sat Jan 10, 2009 7:24 pm Post subject: |
|
|
| Thanx, but will that do hrs or just hr. Like 5 hrs ago or 5 hr ago? |
|
| Back to top |
|
 |
speechles Revered One

Joined: 26 Aug 2006 Posts: 1398 Location: emerald triangle, california (coastal redwoods)
|
Posted: Sat Jan 10, 2009 7:40 pm Post subject: |
|
|
| 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 |
|
 |
intel Halfop
Joined: 26 Feb 2008 Posts: 57
|
Posted: Sat Jan 10, 2009 8:03 pm Post subject: |
|
|
awesome... thanx  |
|
| Back to top |
|
 |
intel Halfop
Joined: 26 Feb 2008 Posts: 57
|
Posted: Mon Jan 12, 2009 8:02 am Post subject: |
|
|
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 |
|
 |
arfer Master

Joined: 26 Nov 2004 Posts: 436 Location: Manchester, UK
|
Posted: Mon Jan 12, 2009 8:14 am Post subject: |
|
|
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 |
|
 |
intel Halfop
Joined: 26 Feb 2008 Posts: 57
|
Posted: Mon Jan 12, 2009 9:36 am Post subject: |
|
|
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 |
|
 |
incith Master

Joined: 23 Apr 2005 Posts: 275 Location: Canada
|
|
| Back to top |
|
 |
intel Halfop
Joined: 26 Feb 2008 Posts: 57
|
Posted: Mon Jan 12, 2009 6:01 pm Post subject: |
|
|
| lol been tryin... used /m /s [m] [s] not working... so obviously doing something wrong. |
|
| Back to top |
|
 |
incith Master

Joined: 23 Apr 2005 Posts: 275 Location: Canada
|
Posted: Mon Jan 12, 2009 8:00 pm Post subject: |
|
|
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 |
|
 |
speechles Revered One

Joined: 26 Aug 2006 Posts: 1398 Location: emerald triangle, california (coastal redwoods)
|
Posted: Mon Jan 12, 2009 8:08 pm Post subject: |
|
|
| 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 |
|
 |
intel Halfop
Joined: 26 Feb 2008 Posts: 57
|
Posted: Mon Jan 12, 2009 9:31 pm Post subject: |
|
|
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 |
|
 |
|